import '~/assets/remark42' import { THEME } from '~/assets/global' import { formatDate } from '~/assets/util' import { IPost, dbPost, initDatabase } from '~/server/db' import styles from '~/styles/PostPage.module.css' import { GetStaticPaths, GetStaticProps } from 'next' import Head from 'next/head' import Link from 'next/link' import { createRef, useEffect } from 'react' const PostPage = (post: IPost) => { const remark42Ref = createRef() useEffect(() => { if (remark42Ref.current) { if (window.remark42Instance) { window.remark42Instance.destroy() } window.remark42Instance = window.REMARK42.createInstance({ node: remark42Ref.current, host: THEME.comment.remark42.host, site_id: THEME.comment.remark42.siteId }) } }, [remark42Ref.current]) return (
{post.title} - {THEME.title} {post.tag ? ( ) : null} {post.image ? ( <> ) : null}

{post.title}

by{' '} {THEME.author.url ? ( {THEME.author.name} ) : ( {THEME.author.name} )} {post.date ? ( {formatDate(post.date)} ) : null}
{post.tag ? (
Tags: {post.tag.map((t) => ( {t} ))}
) : null} {THEME.comment?.remark42 ? ( ) : null}
) } export default PostPage export const getStaticPaths: GetStaticPaths = async () => { await initDatabase() return { paths: dbPost .find() .map(({ path }) => ({ params: { path: path.split(/\//g).map(encodeURIComponent) } })), fallback: false } } export const getStaticProps: GetStaticProps = async (ctx) => { await initDatabase() return { props: dbPost.findOne({ path: (ctx.params.path as string[]).join('/') }) } }