improve handling of draft posts
This commit is contained in:
18
lib/mdx.js
18
lib/mdx.js
@ -85,17 +85,15 @@ export async function getFileBySlug(type, slug) {
|
||||
export async function getAllFilesFrontMatter(type) {
|
||||
const files = fs.readdirSync(path.join(root, 'data', type))
|
||||
|
||||
const allFrontMatter = files.reduce((allPosts, postSlug) => {
|
||||
const source = fs.readFileSync(path.join(root, 'data', type, postSlug), 'utf8')
|
||||
const allFrontMatter = []
|
||||
|
||||
files.forEach((file) => {
|
||||
const source = fs.readFileSync(path.join(root, 'data', type, file), 'utf8')
|
||||
const { data } = matter(source)
|
||||
return [
|
||||
{
|
||||
...data,
|
||||
slug: postSlug.replace(/\.(mdx|md)/, ''),
|
||||
},
|
||||
...allPosts,
|
||||
]
|
||||
}, [])
|
||||
if (data.draft !== true) {
|
||||
allFrontMatter.push({ ...data, slug: file.replace(/\.(mdx|md)/, '') })
|
||||
}
|
||||
})
|
||||
|
||||
return allFrontMatter.sort((a, b) => dateSortDesc(a.date, b.date))
|
||||
}
|
||||
|
Reference in New Issue
Block a user