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 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 Image from 'next/image' 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' import { useGlobal } from '@/lib/global' import { getNotionPageData } from '@/lib/notion/getNotionData' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faAngleDoubleLeft, faAngleDoubleRight, faEye, faFolderOpen } from '@fortawesome/free-solid-svg-icons' const mapPageUrl = id => { return 'https://www.notion.so/' + id.replace(/-/g, '') } const ArticleDetail = ({ post, blockMap, tags, prev, next, allPosts, categories }) => { if (!post) { return } const meta = { title: `${post.title}`, description: post.summary, type: 'article', tags: post.tags } const targetRef = useRef(null) const drawerRight = useRef(null) const url = BLOG.link + useRouter().asPath const { locale } = useGlobal() const date = formatDate(post?.date?.start_date || post.createdTime, BLOG.lang) return
{post.type && !post.type.includes('Page') && (<>
1) ? post.page_cover : BLOG.defaultImgCover} loading='eager' objectFit='cover' layout='fill' alt={post.title} />
)} {/* 文章Title */}

{post.title}


{post.category}
{post.type[0] !== 'Page' && (
{date}
)}
 
{/* Notion文章主体 */} {blockMap && ( )} {/* 推荐文章 */} {/* 版权声明 */}
版权声明
  • 本文作者: {BLOG.author}
  • 本文链接: {url}
  • 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
{/* 标签列表 */}
{post.tagItems && (
{locale.COMMON.TAGS}:
{post.tagItems.map(tag => ( ))}
)}
{prev.title}
{next.title}
{/* 评论互动 */}
{/* 悬浮目录按钮 */}
{ drawerRight.current.handleSwitchVisible() }} /> {/* 目录侧边栏 */}
} export async function getStaticPaths () { let posts = [] if (BLOG.isProd) { posts = await getAllPosts({ from: 'slug - paths', includePage: true }) } return { paths: posts.map(row => `${BLOG.path}/article/${row.slug}`), fallback: true } } export async function getStaticProps ({ params: { slug } }) { const from = `slug-props-${slug}` const notionPageData = await getNotionPageData({ from }) let allPosts = await getAllPosts({ notionPageData, from, includePage: true }) const post = allPosts.find(p => p.slug === slug) if (!post) { return { props: {}, revalidate: 1 } } const blockMap = await getPostBlocks(post.id, 'slug') post.toc = [] if (blockMap) { post.toc = getPageTableOfContents(post, blockMap) } allPosts = allPosts.filter(post => post.type[0] === 'Post') const tagOptions = notionPageData.tagOptions const tags = await getAllTags({ allPosts, tagOptions }) const categories = await getAllCategories(allPosts) // 上一篇、下一篇文章关联 const index = allPosts.indexOf(post) const prev = allPosts.slice(index - 1, index)[0] ?? allPosts.slice(-1)[0] const next = allPosts.slice(index + 1, index + 2)[0] ?? allPosts[0] return { props: { post, blockMap, tags, prev, next, allPosts, categories }, revalidate: 1 } } export default ArticleDetail