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