From f84409e97f1c5490d1ee5f0b7ab4d0fa3e21b7be Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Fri, 7 Jan 2022 17:49:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=A1=B5=E6=A8=A1=E5=BC=8F=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=96=87=E7=AB=A0=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.config.js | 7 +++-- components/ArticleDetail.js | 6 ++-- components/BlogPostCard.js | 50 +++++++++++++++++++++++++------- components/BlogPostListPage.js | 4 +-- components/BlogPostListScroll.js | 15 +++++----- components/Logo.js | 2 +- components/SideAreaLeft.js | 2 ++ components/SideBar.js | 2 -- components/SideBarDrawer.js | 2 +- components/StickyBar.js | 2 +- components/TopNav.js | 26 ++++++++--------- layouts/BaseLayout.js | 3 +- lib/lang/en-US.js | 4 ++- lib/lang/zh-CN.js | 4 ++- lib/notion/getPostBlocks.js | 16 ++++++++++ pages/about.js | 1 + pages/article/[slug].js | 5 ++-- pages/index.js | 33 ++++++++++++++------- pages/page/[page].js | 22 +++++++++----- pages/search.js | 4 +-- styles/notion.css | 5 ++-- 21 files changed, 143 insertions(+), 72 deletions(-) diff --git a/blog.config.js b/blog.config.js index 25f98757..059ad0a9 100644 --- a/blog.config.js +++ b/blog.config.js @@ -9,7 +9,10 @@ const BLOG = { home: { // 首页 showHomeBanner: false, // 首页是否显示大图及标语 [true,false] homeBannerStrings: ['Hi,我是一个程序员', 'Hi,我是一个打工人', 'Hi,我是一个干饭人', '欢迎来到我的博客🎉'], // 首页大图标语文字 - homeBannerImage: './bg_image.jpg' // 背景图地址 + homeBannerImage: './bg_image.jpg', // 背景图地址 + showPostCover: false, // 文章列表显示封面图 + showPreview: true, // 列表展示文章预览 + showSummary: false // 显示用户自定义摘要 }, lang: 'zh-CN', // ['zh-CN','en-US'] default lang => see /lib/lang.js for more. notionPageId: process.env.NOTION_PAGE_ID || 'bee1fccfa3bd47a1a7be83cc71372d83', // Important page_id!!! @@ -23,7 +26,7 @@ const BLOG = { postListStyle: 'page', // ['page','scroll] 文章列表样式:页码分页、单页滚动加载 postsPerPage: 6, // post counts per page sortByDate: false, - autoCollapsedNavBar: true, // the automatically collapsed navigation bar + topNavType: 'normal', // ['fixed','autoCollapse','normal'] 分别是固定顶部、固定底部滑动时自动折叠,不固定 menu: { // 菜单栏设置 showAbout: false, // 显示关于 showCategory: true, // 显示分类 diff --git a/components/ArticleDetail.js b/components/ArticleDetail.js index 3a2e141d..097a5242 100644 --- a/components/ArticleDetail.js +++ b/components/ArticleDetail.js @@ -30,7 +30,7 @@ import WordCount from './WordCount' * @param {*} param0 * @returns */ -export default function ArticleDetail ({ post, blockMap, recommendPosts, prev, next }) { +export default function ArticleDetail ({ post, recommendPosts, prev, next }) { const targetRef = useRef(null) const drawerRight = useRef(null) const url = BLOG.link + useRouter().asPath @@ -125,9 +125,9 @@ export default function ArticleDetail ({ post, blockMap, recommendPosts, prev, n {/* Notion文章主体 */}
- {blockMap && ( + {post.blockMap && ( { +const BlogPostCard = ({ post, showSummary }) => { + const { locale } = useGlobal() return ( -
-
+
- + {post.title} -

{post.summary}

- - - {post?.page_cover && ( + {BLOG.home?.showPostCover && post?.page_cover && ( -
+
{post.title}
@@ -50,4 +76,8 @@ const BlogPostCard = ({ post }) => { ) } +const mapPageUrl = id => { + return 'https://www.notion.so/' + id.replace(/-/g, '') +} + export default BlogPostCard diff --git a/components/BlogPostListPage.js b/components/BlogPostListPage.js index 0162bbd6..4305f986 100644 --- a/components/BlogPostListPage.js +++ b/components/BlogPostListPage.js @@ -18,9 +18,9 @@ const BlogPostListPage = ({ page = 1, posts = [], postCount }) => { return } else { return ( -
+
{/* 文章列表 */} -
+
{posts.map(post => ( ))} diff --git a/components/BlogPostListScroll.js b/components/BlogPostListScroll.js index 154669ca..07fd9be1 100644 --- a/components/BlogPostListScroll.js +++ b/components/BlogPostListScroll.js @@ -1,10 +1,9 @@ -import BlogPostCard from '@/components/BlogPostCard' import BLOG from '@/blog.config' - -import React, { useCallback, useEffect, useRef, useState } from 'react' -import throttle from 'lodash.throttle' +import BlogPostCard from '@/components/BlogPostCard' import BlogPostListEmpty from '@/components/BlogPostListEmpty' import { useGlobal } from '@/lib/global' +import throttle from 'lodash.throttle' +import React, { useCallback, useEffect, useRef, useState } from 'react' /** * 博客列表滚动分页 @@ -14,7 +13,7 @@ import { useGlobal } from '@/lib/global' * @returns {JSX.Element} * @constructor */ -const BlogPostListScroll = ({ posts = [], currentSearch, currentCategory, currentTag }) => { +const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = BLOG.home.showSummary }) => { const postsPerPage = BLOG.postsPerPage const [page, updatePage] = useState(1) const postsToShow = getPostByPage(page, posts, postsPerPage) @@ -53,12 +52,12 @@ const BlogPostListScroll = ({ posts = [], currentSearch, currentCategory, curren if (!postsToShow || postsToShow.length === 0) { return } else { - return
+ return
{/* 文章列表 */} -
+
{postsToShow.map(post => ( - + ))}
diff --git a/components/Logo.js b/components/Logo.js index bc8a2104..6713339e 100644 --- a/components/Logo.js +++ b/components/Logo.js @@ -4,7 +4,7 @@ import React from 'react' const Logo = () => { return -
+
{BLOG.title}
{BLOG.description}
diff --git a/components/SideAreaLeft.js b/components/SideAreaLeft.js index 29351393..832ee465 100644 --- a/components/SideAreaLeft.js +++ b/components/SideAreaLeft.js @@ -30,7 +30,9 @@ const SideAreaLeft = ({ title, tags, currentTag, post, postCount, categories, cu {/* 菜单 */}
+
+
{BLOG.menu.showSearch &&
} diff --git a/components/SideBar.js b/components/SideBar.js index 3e355a0e..31f798d5 100644 --- a/components/SideBar.js +++ b/components/SideBar.js @@ -6,7 +6,6 @@ import { faAngleDoubleRight, faTag, faThList } from '@fortawesome/free-solid-svg import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import Link from 'next/link' import React from 'react' -import Logo from './Logo' /** * 侧边栏 @@ -30,7 +29,6 @@ const SideBar = ({ title, tags, currentTag, post, slot, categories, currentCateg
- {/* 分类 */} {categories && (
diff --git a/components/SideBarDrawer.js b/components/SideBarDrawer.js index a28a288b..87b731d4 100644 --- a/components/SideBarDrawer.js +++ b/components/SideBarDrawer.js @@ -48,7 +48,7 @@ const SideBarDrawer = ({ post, currentTag, cRef, tags, slot, categories, current } return