import { ContentContainer, Page } from "@/components/layouts/layouts"; import { MDXComponentsSet } from "@/components/mdx"; import { DrawerTOC } from "@/components/readerpage/DrawerTOC"; import { PostComments } from "@/components/readerpage/PostComments"; import { PostCover } from "@/components/readerpage/PostCover"; import { ShareButtons } from "@/components/readerpage/ShareButtons"; import { TOC } from "@/components/readerpage/TOC"; import { Toaster } from "@/components/ui/toaster"; import { Footer } from "@/components/utils/Footer"; import { NavBar } from "@/components/utils/NavBar"; import { SEO } from "@/components/utils/SEO"; import { TagBadge } from "@/components/utils/TagBadge"; import { Config } from "@/data/config"; import { normalizeDate } from "@/lib/date"; import { getPostFileContent, sortedPosts } from "@/lib/post-process"; import { getTOCTree } from "@/lib/toc"; import { fontFangZhengXiaoBiaoSongCN, fontSourceSerifScreenCN } from "@/styles/font"; import { TFrontmatter } from "@/types/frontmatter.type"; import { TPostListItem } from "@/types/post-list"; import { TTOCItem } from "@/types/toc.type"; import { nanoid } from "nanoid"; import { GetStaticPaths, GetStaticProps } from "next"; import { MDXRemote, MDXRemoteSerializeResult } from "next-mdx-remote"; import { serialize } from "next-mdx-remote/serialize"; import Link from "next/link"; import { renderToString } from "react-dom/server"; import rehypeAutolinkHeadings from "rehype-autolink-headings"; import rehypeKatex from "rehype-katex"; import rehypePresetMinify from "rehype-preset-minify"; import rehypeRaw from "rehype-raw"; import rehypeSlug from "rehype-slug"; import externalLinks from "remark-external-links"; import remarkGfm from "remark-gfm"; import remarkMath from "remark-math"; import remarkPrism from "remark-prism"; type ReaderPageProps = { source: MDXRemoteSerializeResult; tocList: TTOCItem[]; frontMatter: TFrontmatter; postId: string; nextPostListItem: TPostListItem | null; prevPostListItem: TPostListItem | null; }; const ReaderPage = (props: ReaderPageProps) => { const source = props.source; return ( {props.frontMatter.coverURL && } {props.frontMatter?.title} {props.frontMatter?.subtitle && ( {props.frontMatter.subtitle} )} {normalizeDate(props.frontMatter?.time)} {props.frontMatter?.summary && ( {props.frontMatter?.summary} )} {props.frontMatter.tags && ( {"TAGS : "} {props.frontMatter.tags.map((tagName) => ( ))} )} {source && ( )} {props.prevPostListItem && ( {props.prevPostListItem?.frontMatter.title} )} {props.nextPostListItem && ( {props.nextPostListItem?.frontMatter.title} )} {props.tocList.length > 2 && ( )} {props.tocList.length > 2 && ( )} ); }; export const getStaticPaths: GetStaticPaths<{ id: string }> = async () => { const allPaths = sortedPosts.allPostList.map((item) => ({ params: { id: item.id }, })); return { paths: allPaths, fallback: false, }; }; export const getStaticProps: GetStaticProps = async (context) => { const postId = context.params?.id; if (postId == null || Array.isArray(postId)) { return { notFound: true }; } const source = getPostFileContent(postId); if (source == null) { return { notFound: true }; } const mdxSource = await serialize(source, { parseFrontmatter: true, mdxOptions: { remarkPlugins: [remarkPrism, externalLinks, remarkMath, remarkGfm], rehypePlugins: [rehypeRaw, rehypeKatex as any, rehypeAutolinkHeadings, rehypeSlug, rehypePresetMinify], format: "md", }, }); const tocList = getTOCTree(renderToString()); const postIndexInAllPosts = sortedPosts.allPostList.findIndex((item) => item.id === postId); const frontMatter: TFrontmatter = sortedPosts.allPostList[postIndexInAllPosts].frontMatter; const nextPostListItem = postIndexInAllPosts !== sortedPosts.allPostList.length - 1 ? sortedPosts.allPostList[postIndexInAllPosts + 1] : null; const prevPostListItem = postIndexInAllPosts !== 0 ? sortedPosts.allPostList[postIndexInAllPosts - 1] : null; return { props: { source: mdxSource, tocList: tocList, frontMatter: frontMatter, postId: postId, nextPostListItem: nextPostListItem, prevPostListItem: prevPostListItem, }, }; }; export default ReaderPage;
{props.frontMatter?.summary}