From df6217cf34ea11853052958596a5a6ad4cb8f22d Mon Sep 17 00:00:00 2001 From: Joshua Date: Sat, 27 May 2023 12:47:50 +0200 Subject: [PATCH] add title function so the builder is happy --- src/blog/social-media.md | 2 +- src/pages/blog/[...slug].tsx | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/blog/social-media.md b/src/blog/social-media.md index 187e4a7..c7fff27 100644 --- a/src/blog/social-media.md +++ b/src/blog/social-media.md @@ -1,5 +1,5 @@ --- -title: "[Rant] Social Media is tiring" +title: "[Rant-ish] Social Media is tiring" date: [2023, 05, 27] # hidden: true --- diff --git a/src/pages/blog/[...slug].tsx b/src/pages/blog/[...slug].tsx index 92b88d9..7c6f45c 100644 --- a/src/pages/blog/[...slug].tsx +++ b/src/pages/blog/[...slug].tsx @@ -11,15 +11,20 @@ import Link from "@/components/Link"; import Image from "@/components/Image"; import Head from "next/head"; import matter from "gray-matter"; +import getFrontmatter from "@/lib/getFrontmatter"; +// import post from "" const Post = (props: { post: string, slug: string, matter: any }) => { - // console.log(props.matter) + function title() { + if(!props.matter) return `lio's blog` + else return `${props.matter.title} | lio's blog` + } return (
- {props.matter.title} | lio's blog + {title()}
@@ -47,13 +52,11 @@ const Post = (props: { post: string, slug: string, matter: any }) => { export default Post export async function getStaticProps(context: any) { - let post = await remark() - .use(remarkFrontmatter) - .process(await read(`${listFiles('./src/blog').find(file => file.includes(context.params.slug))}`)) + let post = matter(await (await read(`${listFiles('./src/blog').find(file => file.includes(context.params.slug))}`)).value) return { props: { - post: (post.value as string).replace(/^(---)\n*([a-zA-Z0-9\/\#[\]\"_:,\-\s*]*)(---)$/mi, ""), - matter: matter(post.value).data, + post: (post.content as string).replace(/^(---)\n*([a-zA-Z0-9\/\#[\]\"_:,\-\s*]*)(---)$/mi, ""), + matter: post.data, slug: context.params.slug } } @@ -63,7 +66,6 @@ export async function getStaticProps(context: any) { export async function getStaticPaths() { let path = './src/blog' let paths = listFiles(path).map(file => file.replace(path, "/blog").replace(/.mdx?/gmi, '')) - // console.log(paths) return { paths, fallback: true