2021-06-19 12:02:56 +03:00
|
|
|
import { escape } from '@/lib/utils/htmlEscaper'
|
2021-01-09 17:50:45 +08:00
|
|
|
|
2021-06-18 22:19:29 +03:00
|
|
|
import siteMetadata from '@/data/siteMetadata'
|
2021-06-12 11:37:28 +02:00
|
|
|
|
2021-01-09 17:50:45 +08:00
|
|
|
const generateRssItem = (post) => `
|
|
|
|
<item>
|
2021-01-19 22:03:09 +08:00
|
|
|
<guid>${siteMetadata.siteUrl}/blog/${post.slug}</guid>
|
2021-06-18 22:19:29 +03:00
|
|
|
<title>${escape(post.title)}</title>
|
2021-01-19 22:03:09 +08:00
|
|
|
<link>${siteMetadata.siteUrl}/blog/${post.slug}</link>
|
2021-07-04 19:23:17 +03:00
|
|
|
${post.summary && `<description>${escape(post.summary)}</description>`}
|
2021-01-09 17:50:45 +08:00
|
|
|
<pubDate>${new Date(post.date).toUTCString()}</pubDate>
|
2021-01-13 18:35:20 +08:00
|
|
|
<author>${siteMetadata.email} (${siteMetadata.author})</author>
|
2021-07-04 16:10:41 +08:00
|
|
|
${post.tags && post.tags.map((t) => `<category>${t}</category>`).join('')}
|
2021-01-09 17:50:45 +08:00
|
|
|
</item>
|
|
|
|
`
|
|
|
|
|
2021-01-13 18:35:20 +08:00
|
|
|
const generateRss = (posts, page = 'index.xml') => `
|
2021-01-09 17:50:45 +08:00
|
|
|
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
|
|
|
<channel>
|
2021-06-18 22:19:29 +03:00
|
|
|
<title>${escape(siteMetadata.title)}</title>
|
2021-01-09 17:50:45 +08:00
|
|
|
<link>${siteMetadata.siteUrl}/blog</link>
|
2021-06-18 22:19:29 +03:00
|
|
|
<description>${escape(siteMetadata.description)}</description>
|
2021-01-09 17:50:45 +08:00
|
|
|
<language>${siteMetadata.language}</language>
|
2021-01-13 18:35:20 +08:00
|
|
|
<managingEditor>${siteMetadata.email} (${siteMetadata.author})</managingEditor>
|
|
|
|
<webMaster>${siteMetadata.email} (${siteMetadata.author})</webMaster>
|
2021-01-09 17:50:45 +08:00
|
|
|
<lastBuildDate>${new Date(posts[0].date).toUTCString()}</lastBuildDate>
|
2021-01-13 18:35:20 +08:00
|
|
|
<atom:link href="${siteMetadata.siteUrl}/${page}" rel="self" type="application/rss+xml"/>
|
2021-01-09 17:50:45 +08:00
|
|
|
${posts.map(generateRssItem).join('')}
|
|
|
|
</channel>
|
|
|
|
</rss>
|
|
|
|
`
|
|
|
|
export default generateRss
|