refactor formatSlug logic

This commit is contained in:
Timothy
2021-01-16 18:38:45 +08:00
parent 8f646e3429
commit 0403eb24a8
2 changed files with 7 additions and 3 deletions

View File

@ -28,6 +28,10 @@ export async function getFiles(type) {
return fs.readdirSync(path.join(root, 'data', type))
}
export function formatSlug(slug) {
return slug.replace(/\.(mdx|md)/, '')
}
export function dateSortDesc(a, b) {
if (a > b) return -1
if (a < b) return 1
@ -91,7 +95,7 @@ export async function getAllFilesFrontMatter(type) {
const source = fs.readFileSync(path.join(root, 'data', type, file), 'utf8')
const { data } = matter(source)
if (data.draft !== true) {
allFrontMatter.push({ ...data, slug: file.replace(/\.(mdx|md)/, '') })
allFrontMatter.push({ ...data, slug: formatSlug(file) })
}
})