www/pages/posts/[post].tsx

67 lines
1.7 KiB
TypeScript
Raw Normal View History

import Layout from '../../components/layout';
import ReactMarkdown from 'react-markdown';
import style from '../../styles/post.module.css';
import PostsInfo from '../../public/posts.json';
import readMarkdown from '../../lib/read-markdown';
interface Post {
title: string;
mtime: string;
otime?: string;
}
interface Posts {
[slug: string]: Post
}
function Post({ post }: { post: Post & { content: string, cover?: string } }) {
return (<>
<Layout removeContainer={true} >
{<div className={style.imageBlock}
style={{
backgroundImage:
post.cover ?
`url(/assets/images/${post.cover})` :
'linear-gradient(to bottom right, #565a0f, #08432c 15%, rgb(5, 39, 10) 40%, rgb(0, 22, 46) 80%)'
2022-10-05 03:41:59 +00:00
}}></div>}
2022-05-15 13:56:45 +00:00
<div className={style.spacer}></div>
<section className={`${style.block} block`}>
2022-10-05 03:41:59 +00:00
<div className='container'>
<ReactMarkdown>{post.content}</ReactMarkdown>
</div>
2022-05-15 13:56:45 +00:00
</section>
</Layout>
2022-04-27 09:10:49 +00:00
</>
);
}
export async function getStaticProps({ params }: any) {
const postsInfo: Posts = PostsInfo;
const post: Post = postsInfo[params.post];
return {
props: {
post: {
...post,
content: await readMarkdown('posts', params.post, true)
}
}
}
}
export async function getStaticPaths() {
return {
paths: Object.keys(PostsInfo).map((post: string) => {
return {
params: {
post
}
}
}),
fallback: false
};
}
export default Post;