2022-07-17 21:40:41 +08:00
|
|
|
import { escape } from '@/lib/utils/htmlEscaper'
|
|
|
|
|
|
|
|
import siteMetadata from '@/data/siteMetadata'
|
2022-10-07 13:55:39 +08:00
|
|
|
import { PostFrontMatter } from 'types/PostFrontMatter'
|
2022-07-17 21:40:41 +08:00
|
|
|
|
2022-10-07 13:55:39 +08:00
|
|
|
const generateRssItem = (post: PostFrontMatter) => `
|
2022-07-17 21:40:41 +08:00
|
|
|
<item>
|
|
|
|
<guid>${siteMetadata.siteUrl}/blog/${post.slug}</guid>
|
|
|
|
<title>${escape(post.title)}</title>
|
|
|
|
<link>${siteMetadata.siteUrl}/blog/${post.slug}</link>
|
|
|
|
${post.summary && `<description>${escape(post.summary)}</description>`}
|
|
|
|
<pubDate>${new Date(post.date).toUTCString()}</pubDate>
|
|
|
|
<author>${siteMetadata.email} (${siteMetadata.author})</author>
|
|
|
|
${post.tags && post.tags.map((t) => `<category>${t}</category>`).join('')}
|
|
|
|
</item>
|
|
|
|
`
|
|
|
|
|
2022-10-07 13:55:39 +08:00
|
|
|
const generateRss = (posts: PostFrontMatter[], page = 'feed.xml') => `
|
2022-07-17 21:40:41 +08:00
|
|
|
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
|
|
|
<channel>
|
|
|
|
<title>${escape(siteMetadata.title)}</title>
|
|
|
|
<link>${siteMetadata.siteUrl}/blog</link>
|
|
|
|
<description>${escape(siteMetadata.description)}</description>
|
|
|
|
<language>${siteMetadata.language}</language>
|
|
|
|
<managingEditor>${siteMetadata.email} (${siteMetadata.author})</managingEditor>
|
|
|
|
<webMaster>${siteMetadata.email} (${siteMetadata.author})</webMaster>
|
|
|
|
<lastBuildDate>${new Date(posts[0].date).toUTCString()}</lastBuildDate>
|
|
|
|
<atom:link href="${siteMetadata.siteUrl}/${page}" rel="self" type="application/rss+xml"/>
|
|
|
|
${posts.map(generateRssItem).join('')}
|
|
|
|
</channel>
|
|
|
|
</rss>
|
|
|
|
`
|
|
|
|
export default generateRss
|