From 3d02abf98e34df2e0ee259ba4b0c839bf45dea65 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 1 Dec 2021 13:23:03 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20404=E9=A1=B5=E9=9D=A2=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E6=96=87=E7=AB=A0=E5=8A=A0=E8=BD=BD=EF=BC=9B=20Page?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=8E=92=E7=89=88=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + components/RewardButton.js | 5 +- pages/404.js | 8 ++- pages/article/[slug].js | 118 ++++++++++++++++++------------------- 4 files changed, 66 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index 925ba98e..8622c2c2 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ - 评论、搜索、标签、分类 - 订阅、网站统计 - 本地化多语言 +- 服务端渲染、优秀的SEO **🎨  美观,轻松自定义** diff --git a/components/RewardButton.js b/components/RewardButton.js index f431ca1a..3726710f 100644 --- a/components/RewardButton.js +++ b/components/RewardButton.js @@ -5,9 +5,8 @@ import React from 'react' * @returns {JSX.Element} * @constructor */ -const RewardButton = () => { +const RewardButton = () => { const [popoverShow, setPopoverShow] = React.useState(false) - const btnRef = React.createRef() const openPopover = () => { setPopoverShow(true) @@ -16,7 +15,7 @@ const RewardButton = () => { setPopoverShow(false) } return ( -
+
打赏一杯咖啡 diff --git a/pages/404.js b/pages/404.js index c2a21083..ade77625 100644 --- a/pages/404.js +++ b/pages/404.js @@ -11,8 +11,14 @@ import { useRouter } from 'next/router' export default function Custom404 () { const router = useRouter() useEffect(() => { + // 延时3秒如果加载失败就返回首页 setTimeout(() => { - router.push('/') + if (window) { + const article = document.getElementById('article-wrapper') + if (!article) { + router.push('/') + } + } }, 3000) }) diff --git a/pages/article/[slug].js b/pages/article/[slug].js index cfc27311..28d4da7e 100644 --- a/pages/article/[slug].js +++ b/pages/article/[slug].js @@ -47,75 +47,71 @@ const ArticleDetail = ({ post, blockMap, tags, prev, next, posts, categories }) return -
+
{/* 中央区域 wrapper */} -
- {/* 封面图 */} - {post.page_cover && post.page_cover.length > 1 && ( - {post.title} - )} -
+ {post.type && !post.type.includes('Page') && (<> +
+ {/* 封面图 */} + {post.page_cover && post.page_cover.length > 1 && ( + {post.title} + )} +
+ )}
- {/* 文章标题 */} -

- {post.title} -

-

- {post.summary} -

+ {post.type && !post.type.includes('Page') && (<> + {/* 文章信息 */} +

{post.title}

+

{post.summary}

+
+
+
+ {locale.COMMON.CATEGORY}: +
+ +
{post.category}
+ - {/* 文章作者等关联信息 */} -
-
-
- {locale.COMMON.CATEGORY}: -
- -
{post.category}
- - - {post.type[0] !== 'Page' && ( -
- {formatDate( - post?.date?.start_date || post.createdTime, - BLOG.lang + {post.type[0] !== 'Page' && ( +
+ {formatDate( + post?.date?.start_date || post.createdTime, + BLOG.lang + )} +
)}
- )} -
- {/* 不蒜子 */} -
-
-   + {/* 不蒜子 */} +
+
+   +
+
-
-
+ )} -
- {/* Notion文章主体 */} - {blockMap && ( - - )} -
+ {/* Notion文章主体 */} + {blockMap && ( + + )} -
- -
+ {/* 赞赏按钮 */} + + {/* 推荐文章 */} {/* 版权声明 */} @@ -128,8 +124,8 @@ const ArticleDetail = ({ post, blockMap, tags, prev, next, posts, categories }) + {/* 标签列表 */}
- {post.tagItems && (
{locale.COMMON.TAGS}:
@@ -138,13 +134,12 @@ const ArticleDetail = ({ post, blockMap, tags, prev, next, posts, categories }) ))}
)} -
-
+ {/* 上一篇下一篇文章 */}

@@ -168,6 +163,7 @@ const ArticleDetail = ({ post, blockMap, tags, prev, next, posts, categories })
+ {/* 悬浮目录按钮 */}
{ drawerRight.current.handleSwitchVisible() @@ -183,7 +179,6 @@ export async function getStaticPaths () { let posts = [] if (BLOG.isProd) { posts = await getAllPosts({ from: 'slug - paths', includePage: true }) - posts = posts.filter(post => post.status[0] === 'Published') } return { paths: posts.map(row => `${BLOG.path}/article/${row.slug}`), @@ -192,8 +187,7 @@ export async function getStaticPaths () { } export async function getStaticProps ({ params: { slug } }) { - let posts = await getAllPosts({ from: 'slug-props' }) - posts = posts.filter(post => post.status[0] === 'Published') + let posts = await getAllPosts({ from: 'slug-props', includePage: true }) const post = posts.find(t => t.slug === slug) if (!post) { return {