Skip to content

Commit

Permalink
chore: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Jan 11, 2024
1 parent 5054353 commit 4955f78
Showing 1 changed file with 41 additions and 39 deletions.
80 changes: 41 additions & 39 deletions packages/fff-flavored-frontmatter/src/utils/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,45 +67,47 @@ export type JSONFeedItemAttachment = {
* @returns JSON Feed Item Object (without content_\{text,html\} / id / url)
* @see {@link https://jsonfeed.org/version/1.1}
*/
export const toJSONFeedItem
= <TInput extends Partial<JSONFeedItem> = Partial<JSONFeedItem>, TOutput extends TInput = TInput & { _indieweb: JSONFeedItemIndieWeb }>(fm: FFFFlavoredFrontmatter & Record<string, unknown>, item?: TInput): TOutput => {
fm = transform(fm as Record<string, unknown>, [strict({
categories: false,
media: {
array: false,
type: 'string',
},
})])
return {
...item,
/**
* Treats keys starts with underscore as Custom JSON Feed Extensions
* @see {@link https://www.jsonfeed.org/version/1.1/#extensions-a-name-extensions-a}
*/
...Object.fromEntries(
Object.entries(fm)
.filter(([key, value]) => key.startsWith('_') && typeof value === 'object'),
),
_indieweb: {
'bookmark-of': fm.bookmark_of,
'in-reply-to': fm.in_reply_to,
'like-of': fm.like_of,
'repost-of': fm.repost_of,
'syndication': fm.syndication,
'type': postTypeDiscovery(fm),
...fm._indieweb as Partial<JSONFeedItemIndieWeb>,
...item?._indieweb as Partial<JSONFeedItemIndieWeb>,
},
authors: fm.authors,
date_modified: fm.updated,
date_published: fm.published ?? fm.created,
image: fm.image,
language: fm.lang,
summary: fm.summary,
tags: fm.tags,
title: fm.title,
} as JSONFeedItem as TOutput
}
export const toJSONFeedItem = <
TInput extends Partial<JSONFeedItem> = Partial<JSONFeedItem>,
TOutput extends TInput = TInput & { _indieweb: JSONFeedItemIndieWeb }
>(fm: FFFFlavoredFrontmatter & Record<string, unknown>, item?: TInput): TOutput => {
fm = transform(fm as Record<string, unknown>, [strict({
categories: false,
media: {
array: false,
type: 'string',
},
})])
return {
...item,
/**
* Treats keys starts with underscore as Custom JSON Feed Extensions
* @see {@link https://www.jsonfeed.org/version/1.1/#extensions-a-name-extensions-a}
*/
...Object.fromEntries(
Object.entries(fm)
.filter(([key, value]) => key.startsWith('_') && typeof value === 'object'),
),
_indieweb: {
'bookmark-of': fm.bookmark_of,
'in-reply-to': fm.in_reply_to,
'like-of': fm.like_of,
'repost-of': fm.repost_of,
'syndication': fm.syndication,
'type': postTypeDiscovery(fm),
...fm._indieweb as Partial<JSONFeedItemIndieWeb>,
...item?._indieweb as Partial<JSONFeedItemIndieWeb>,
},
authors: fm.authors,
date_modified: fm.updated,
date_published: fm.published ?? fm.created,
image: fm.image,
language: fm.lang,
summary: fm.summary,
tags: fm.tags,
title: fm.title,
} as JSONFeedItem as TOutput
}

/**
* From FFF to JF2 Feed Child (Editor's Draft 09 February 2019)
Expand Down

0 comments on commit 4955f78

Please sign in to comment.