import { ContentContainer, Page } from "@/components/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 { Separator } from "@/components/ui/separator"; 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 { Config } from "@/data/config"; import { normalizeDate } from "@/lib/date"; import { getPostFileContent, sortedPosts } from "@/lib/post-process"; import { getTOCTree } from "@/lib/toc"; import useDrawerTOCState from "@/stores/useDrawerTOCState"; 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 { useSwipeable } from "react-swipeable"; 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 = { compiledSource: MDXRemoteSerializeResult; tocList: TTOCItem[]; frontMatter: TFrontmatter; postId: string; nextPostListItem: TPostListItem | null; prevPostListItem: TPostListItem | null; }; const ReaderPage = (props: ReaderPageProps) => { const compiledSource = props.compiledSource; const setIsTOCOpen = useDrawerTOCState((state) => state.changeDrawerTOCOpen); // Only the TOC length reaches 3 can be displayed. // In order to avoid large blank spaces that ruin the visual perception const isTOCLongEnough = props.tocList.length > 4; const handleRightSwipe = useSwipeable({ onSwipedRight: () => { isTOCLongEnough && setIsTOCOpen(true); }, delta: 150, }); 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) => ( {tagName} ))}
)}
{compiledSource && ( )}
    {props.prevPostListItem && (
  • {props.prevPostListItem?.frontMatter.title}
  • )} {props.nextPostListItem && (
  • {props.nextPostListItem?.frontMatter.title}
  • )}
{isTOCLongEnough && (
)}
{isTOCLongEnough && (
)}