Merge pull request #293 from timlrx/fix/draft-post

fix: do not generate rss if no valid posts
This commit is contained in:
Timothy 2021-12-15 17:11:50 +08:00 committed by GitHub
commit 004ac216bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -32,8 +32,10 @@ export async function getStaticProps({ params }) {
const authorDetails = await Promise.all(authorPromise) const authorDetails = await Promise.all(authorPromise)
// rss // rss
const rss = generateRss(allPosts) if (allPosts.length > 0) {
fs.writeFileSync('./public/feed.xml', rss) const rss = generateRss(allPosts)
fs.writeFileSync('./public/feed.xml', rss)
}
return { props: { post, authorDetails, prev, next } } return { props: { post, authorDetails, prev, next } }
} }

View File

@ -30,10 +30,12 @@ export async function getStaticProps({ params }) {
) )
// rss // rss
const rss = generateRss(filteredPosts, `tags/${params.tag}/feed.xml`) if (filteredPosts.length > 0) {
const rssPath = path.join(root, 'public', 'tags', params.tag) const rss = generateRss(filteredPosts, `tags/${params.tag}/feed.xml`)
fs.mkdirSync(rssPath, { recursive: true }) const rssPath = path.join(root, 'public', 'tags', params.tag)
fs.writeFileSync(path.join(rssPath, 'feed.xml'), rss) fs.mkdirSync(rssPath, { recursive: true })
fs.writeFileSync(path.join(rssPath, 'feed.xml'), rss)
}
return { props: { posts: filteredPosts, tag: params.tag } } return { props: { posts: filteredPosts, tag: params.tag } }
} }