feat: map author details to blog post

This commit is contained in:
Timothy Lin
2021-05-16 15:56:39 +08:00
parent 84f00d6fc6
commit b380a6f15a
2 changed files with 9 additions and 7 deletions

View File

@ -24,21 +24,23 @@ export async function getStaticProps({ params }) {
const prev = allPosts[postIndex + 1] || null
const next = allPosts[postIndex - 1] || null
const post = await getFileBySlug('blog', params.slug)
const postAuthor = post.frontMatter.author || 'default'
const { frontMatter: authorDetails } = await getFileBySlug('authors', [postAuthor])
// rss
const rss = generateRss(allPosts)
fs.writeFileSync('./public/index.xml', rss)
return { props: { post, prev, next } }
return { props: { post, authorDetails, prev, next } }
}
export default function Blog({ post, prev, next }) {
export default function Blog({ post, authorDetails, prev, next }) {
const { mdxSource, frontMatter } = post
return (
<>
{frontMatter.draft !== true ? (
<PostLayout frontMatter={frontMatter} prev={prev} next={next}>
<PostLayout frontMatter={frontMatter} authorDetails={authorDetails} prev={prev} next={next}>
<MDXRemote {...mdxSource} components={MDXComponents} />
</PostLayout>
) : (