add title function so the builder is happy
This commit is contained in:
parent
9540cab4bb
commit
df6217cf34
2 changed files with 11 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
title: "[Rant] Social Media is tiring"
|
title: "[Rant-ish] Social Media is tiring"
|
||||||
date: [2023, 05, 27]
|
date: [2023, 05, 27]
|
||||||
# hidden: true
|
# hidden: true
|
||||||
---
|
---
|
||||||
|
|
|
@ -11,15 +11,20 @@ import Link from "@/components/Link";
|
||||||
import Image from "@/components/Image";
|
import Image from "@/components/Image";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import matter from "gray-matter";
|
import matter from "gray-matter";
|
||||||
|
import getFrontmatter from "@/lib/getFrontmatter";
|
||||||
|
// import post from ""
|
||||||
const Post = (props: { post: string, slug: string, matter: any }) => {
|
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 (
|
return (
|
||||||
<RenderWithoutJS>
|
<RenderWithoutJS>
|
||||||
<main id={index.layout}>
|
<main id={index.layout}>
|
||||||
<Head>
|
<Head>
|
||||||
<title>{props.matter.title} | lio's blog</title>
|
<title>{title()}</title>
|
||||||
</Head>
|
</Head>
|
||||||
<Sidebar />
|
<Sidebar />
|
||||||
<section id={index.main}>
|
<section id={index.main}>
|
||||||
|
@ -47,13 +52,11 @@ const Post = (props: { post: string, slug: string, matter: any }) => {
|
||||||
export default Post
|
export default Post
|
||||||
|
|
||||||
export async function getStaticProps(context: any) {
|
export async function getStaticProps(context: any) {
|
||||||
let post = await remark()
|
let post = matter(await (await read(`${listFiles('./src/blog').find(file => file.includes(context.params.slug))}`)).value)
|
||||||
.use(remarkFrontmatter)
|
|
||||||
.process(await read(`${listFiles('./src/blog').find(file => file.includes(context.params.slug))}`))
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
post: (post.value as string).replace(/^(---)\n*([a-zA-Z0-9\/\#[\]\"_:,\-\s*]*)(---)$/mi, ""),
|
post: (post.content as string).replace(/^(---)\n*([a-zA-Z0-9\/\#[\]\"_:,\-\s*]*)(---)$/mi, ""),
|
||||||
matter: matter(post.value).data,
|
matter: post.data,
|
||||||
slug: context.params.slug
|
slug: context.params.slug
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +66,6 @@ export async function getStaticProps(context: any) {
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
let path = './src/blog'
|
let path = './src/blog'
|
||||||
let paths = listFiles(path).map(file => file.replace(path, "/blog").replace(/.mdx?/gmi, ''))
|
let paths = listFiles(path).map(file => file.replace(path, "/blog").replace(/.mdx?/gmi, ''))
|
||||||
// console.log(paths)
|
|
||||||
return {
|
return {
|
||||||
paths,
|
paths,
|
||||||
fallback: true
|
fallback: true
|
||||||
|
|
Loading…
Add table
Reference in a new issue