-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
85 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,70 @@ | ||
import { createMarkdownProcessor } from '@astrojs/markdown-remark'; | ||
|
||
import { Feed } from 'feed'; | ||
|
||
import { getAllPosts } from '@/modules/post/common'; | ||
import { ROUTES } from '@/constants/routes'; | ||
import { CONFIG } from '@/config'; | ||
import { renderMarkdown } from '@/utils/markdown'; | ||
|
||
import type { Item } from 'feed'; | ||
|
||
const { SITE_DESCRIPTION, SITE_TITLE, SITE_URL } = CONFIG; | ||
const { SITE_DESCRIPTION, SITE_TITLE, SITE_URL, AUTHOR_NAME, AUTHOR_EMAIL } = CONFIG; | ||
|
||
const author = { | ||
name: 'Nemanja Mitic', | ||
email: '[email protected]', | ||
link: `${SITE_URL}/about`, | ||
}; | ||
const copyright = (date: Date) => `©${date.getFullYear()} copyright text`; | ||
export const getFeed = async (): Promise<Feed> => { | ||
const author = { | ||
name: AUTHOR_NAME, | ||
email: AUTHOR_EMAIL, | ||
link: `${SITE_URL}${ROUTES.ABOUT}`, | ||
}; | ||
|
||
export const feed = new Feed({ | ||
title: SITE_TITLE, | ||
description: SITE_DESCRIPTION, | ||
id: SITE_URL, | ||
link: SITE_URL, | ||
language: 'en', | ||
image: `${SITE_URL}/images/favicons/favicon-32x32.png`, | ||
favicon: `${SITE_URL}/favicon.ico`, | ||
copyright: copyright(new Date()), | ||
updated: new Date(), | ||
feedLinks: { | ||
json: `${SITE_URL}/feed.json`, | ||
rss: `${SITE_URL}/feed.xml`, | ||
}, | ||
author, | ||
}); | ||
const copyright = (date: Date) => | ||
`©${date.getFullYear()} ${AUTHOR_NAME}. All rights reserved.`; | ||
|
||
const sortedRawPosts = await getAllPosts(); | ||
const feed = new Feed({ | ||
title: SITE_TITLE, | ||
description: SITE_DESCRIPTION, | ||
id: SITE_URL, | ||
link: SITE_URL, | ||
language: 'en', | ||
image: `${SITE_URL}/images/favicons/favicon-32x32.png`, | ||
favicon: `${SITE_URL}/favicon.ico`, | ||
copyright: copyright(new Date()), | ||
updated: new Date(), | ||
feedLinks: { | ||
json: `${SITE_URL}${ROUTES.API.FEED_JSON}`, | ||
rss: `${SITE_URL}${ROUTES.API.FEED_RSS}`, | ||
}, | ||
author, | ||
}); | ||
|
||
const { render: renderMarkdown } = await createMarkdownProcessor({}); | ||
const sortedPosts = await getAllPosts(); | ||
|
||
for (const post of sortedRawPosts) { | ||
const match = post.slug.match(/^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})-(?<slug>.+)/); | ||
if (!match || !post.slug || post.data.draft) { | ||
continue; | ||
} | ||
const slug = Object.values(match.groups!).join('/'); | ||
for (const post of sortedPosts) { | ||
const { data, body, slug } = post; | ||
const { title, description, publishDate, heroImage, noHero, draft } = data; | ||
|
||
const url = `${SITE_URL}${ROUTES.BLOG}${slug}/`; | ||
const { code: description } = await renderMarkdown( | ||
`${post.data.description || ''}\n\n[Continue reading…](${url})` | ||
); | ||
const { code: content } = await renderMarkdown(post.body); | ||
// omit drafts | ||
if (draft) continue; | ||
|
||
const item: Item = { | ||
title: post.data.title, | ||
description, | ||
id: url, | ||
link: url, | ||
date: post.data.publishDate, | ||
published: post.data.publishDate, | ||
author: [author], | ||
copyright: copyright(post.data.publishDate), | ||
content, | ||
}; | ||
if (post.data.heroImage?.src) { | ||
item.image = `${SITE_URL}${post.data.heroImage.src}`; | ||
const url = `${SITE_URL}${ROUTES.BLOG}${slug}/`; | ||
const { code: content } = await renderMarkdown(body); | ||
|
||
const item: Item = { | ||
title, | ||
description, | ||
id: url, | ||
link: url, | ||
date: publishDate, | ||
published: publishDate, | ||
author: [author], | ||
copyright: copyright(publishDate), | ||
content, | ||
...(noHero ? { image: `${SITE_URL}${heroImage.src}` } : {}), | ||
}; | ||
|
||
feed.addItem(item); | ||
} | ||
|
||
feed.addItem(item); | ||
} | ||
return feed; | ||
}; | ||
|
||
export const feed = await getFeed(); |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters