feat: allow user to modify rss feed page name

This commit is contained in:
Timothy Lin 2023-07-23 23:01:00 +08:00
parent 6140ff7780
commit ed0b0eb953

View File

@ -1,6 +1,5 @@
import { writeFileSync, mkdirSync } from 'fs'
import path from 'path'
// import { generateRSS } from 'pliny/utils/generate-rss.js'
import GithubSlugger from 'github-slugger'
import siteMetadata from '../data/siteMetadata.js'
import tagData from '../app/tag-data.json' assert { type: 'json' }
@ -34,12 +33,12 @@ const generateRss = (config, posts, page = 'feed.xml') => `
</rss>
`
async function generateRSS(config, allBlogs) {
async function generateRSS(config, allBlogs, page = 'feed.xml') {
const publishPosts = allBlogs.filter((post) => post.draft !== true)
// RSS for blog post
if (publishPosts.length > 0) {
const rss = generateRss(config, publishPosts)
writeFileSync('./public/feed.xml', rss)
writeFileSync(`./public/${page}`, rss)
}
if (publishPosts.length > 0) {
@ -47,10 +46,10 @@ async function generateRSS(config, allBlogs) {
const filteredPosts = allBlogs.filter((post) =>
post.tags.map((t) => GithubSlugger.slug(t)).includes(tag)
)
const rss = generateRss(config, filteredPosts, `tags/${tag}/feed.xml`)
const rss = generateRss(config, filteredPosts, `tags/${tag}/${page}`)
const rssPath = path.join('public', 'tags', tag)
mkdirSync(rssPath, { recursive: true })
writeFileSync(path.join(rssPath, 'feed.xml'), rss)
writeFileSync(path.join(rssPath, page), rss)
}
}
}