import { 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 Image from 'next/image' 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 BlogPostMini from '@/components/BlogPostMini' import Comment from '@/components/Comment' import TocBar from '@/components/TocBar' import BaseLayout from '@/layouts/BaseLayout' import { useRef } from 'react' import Custom404 from '@/pages/404' const mapPageUrl = id => { return 'https://www.notion.so/' + id.replace(/-/g, '') } const BlogPost = ({ post, blockMap, tags, prev, next, posts }) => { if (!post) { return } const meta = { title: post.title, description: post.summary, type: 'article' } const targetRef = useRef(null) const url = BLOG.link + useRouter().asPath return {/* 阅读进度条 */}
{/* 中央区域 wrapper */}
{/* 封面图 */} {post.page_cover && post.page_cover.length > 1 && ( {post.title} )}
{/* 文章标题 */}

{post.title}

{/* 文章信息 */}
{post.slug !== 'about' && (<> {BLOG.author} )} {post.tags && (
{post.tags.map(tag => ( ))}
)} {post.type[0] !== 'Page' && (
{formatDate( post?.date?.start_date || post.createdTime, BLOG.lang )}
)}
{/* 不蒜子 */}
{/* Notion文章主体 */} {blockMap && ( )}

- 💖 本 文 结 束 😚 感 谢 您 的 阅 读 💖 -

{/* 版权声明 */}
  • 本文作者:{BLOG.author}
  • 本文链接: {url} 《{post.title}》
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
分享本文 
继续阅读
{/* 评论互动 */}
{/* 右侧目录 */}
} 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 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 }, revalidate: 1 } } export default BlogPost