Merge pull request #159 from timlrx/fix/date

fix: support date type in blog frontmatter
This commit is contained in:
Timothy 2021-08-05 22:31:12 +08:00 committed by GitHub
commit 47c8a819cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 6 deletions

View File

@ -1,7 +1,7 @@
---
title: 'Introducing Tailwind Nexjs Starter Blog'
title: 'Introducing Tailwind Nextjs Starter Blog'
date: '2021-01-12'
lastmod: '2021-07-28'
lastmod: '2021-08-02'
tags: ['next-js', 'tailwind', 'guide']
draft: false
summary: 'Looking for a performant, out of the box template, with all the best in web technology to support your blogging needs? Checkout the Tailwind Nextjs Starter Blog template.'

View File

@ -1,6 +1,6 @@
---
title: 'New features in v1'
date: '2021-07-28'
date: 2021-07-28T15:32:14Z
tags: ['next-js', 'tailwind', 'guide']
draft: false
summary: 'An overview of the new features released in v1 - code block copy, multiple authors, frontmatter layout and more'

View File

@ -116,6 +116,7 @@ export async function getFileBySlug(type, slug) {
slug: slug || null,
fileName: fs.existsSync(mdxPath) ? `${slug}.mdx` : `${slug}.md`,
...frontmatter,
date: frontmatter.date ? new Date(frontmatter.date).toISOString() : null,
},
}
}
@ -135,9 +136,13 @@ export async function getAllFilesFrontMatter(folder) {
return
}
const source = fs.readFileSync(file, 'utf8')
const { data } = matter(source)
if (data.draft !== true) {
allFrontMatter.push({ ...data, slug: formatSlug(fileName) })
const { data: frontmatter } = matter(source)
if (frontmatter.draft !== true) {
allFrontMatter.push({
...frontmatter,
slug: formatSlug(fileName),
date: frontmatter.date ? new Date(frontmatter.date).toISOString() : null,
})
}
})