import { getAllCategories, getAllPosts, getAllTags, getPostBlocks } from '@/lib/notion' import BLOG from '@/blog.config' import { getPageTableOfContents } from 'notion-utils' import { useRouter } from 'next/router' import Progress from '@/components/Progress' import TagItem from '@/components/TagItem' import formatDate from '@/lib/formatDate' import { Code, Collection, CollectionRow, Equation, NotionRenderer } from 'react-notion-x' import RewardButton from '@/components/RewardButton' import ShareBar from '@/components/ShareBar' import Comment from '@/components/Comment' import BaseLayout from '@/layouts/BaseLayout' import React, { useRef } from 'react' import Custom404 from '@/pages/404' import Link from 'next/link' import 'prismjs/themes/prism-okaidia.css' import 'prismjs' import 'prismjs/components/prism-bash' import 'prismjs/components/prism-markup' import 'prismjs/components/prism-python' import 'prismjs/components/prism-javascript' import 'prismjs/components/prism-typescript' import RecommendPosts from '@/components/RecommendPosts' import TocDrawer from '@/components/TocDrawer' import TocDrawerButton from '@/components/TocDrawerButton' const mapPageUrl = id => { return 'https://www.notion.so/' + id.replace(/-/g, '') } const ArticleDetail = ({ post, blockMap, tags, prev, next, posts, categories }) => { if (!post) { return } const meta = { title: `${post.title} | ${BLOG.title}`, description: post.summary, type: 'article', tags: post.tags } const targetRef = useRef(null) const drawerRight = useRef(null) const url = BLOG.link + useRouter().asPath return
{/* 中央区域 wrapper */}
{/* 封面图 */} {post.page_cover && post.page_cover.length > 1 && ( {post.title} )}
{/* 文章标题 */}

{post.title}

{post.summary}

{/* 文章作者等关联信息 */}
分类:
{post.category}
{post.type[0] !== 'Page' && (
{formatDate( post?.date?.start_date || post.createdTime, BLOG.lang )}
)}
{/* 不蒜子 */}
{/* Notion文章主体 */} {blockMap && ( )}
{/* 版权声明 */}
  • 本文作者:{BLOG.author}
  • 本文链接: {url} 《{post.title}》
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
{post.tags && (
标签:
{post.tags.map(tag => ( ))}
)}

{prev.title}
{next.title}
{/* 评论互动 */}
{ drawerRight.current.handleSwitchVisible() }} /> {/* 目录侧边栏 */}
} export async function getStaticPaths () { let posts = await getAllPosts({ from: 'slug - paths' }) posts = posts.filter(post => post.status[0] === 'Published') return { paths: posts.map(row => `${BLOG.path}/article/${row.slug}`), fallback: true } } export async function getStaticProps ({ params: { slug } }) { let posts = await getAllPosts({ from: 'slug-props' }) posts = posts.filter(post => post.status[0] === 'Published') const post = posts.find(t => t.slug === slug) if (!post) { return { props: {}, revalidate: 1 } } const blockMap = await getPostBlocks(post.id, 'slug') if (blockMap) { post.toc = getPageTableOfContents(post, blockMap) } else { post.toc = [] } posts = posts.filter(post => post.type[0] === 'Post') const tags = await getAllTags(posts) const categories = await getAllCategories(posts) // 获取推荐文章 const index = posts.indexOf(post) const prev = posts.slice(index - 1, index)[0] ?? posts.slice(-1)[0] const next = posts.slice(index + 1, index + 2)[0] ?? posts[0] return { props: { post, blockMap, tags, prev, next, posts, categories }, revalidate: 1 } } export default ArticleDetail