From f98dc6a93781b284e94d577bf3e6c3d624a4408e Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Fri, 7 Jan 2022 14:27:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6notionData=20=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/BlogPostListPage.js | 30 ++----------- components/LatestPostsGroup.js | 31 ++++++-------- components/SideAreaLeft.js | 5 +-- components/SideAreaRight.js | 19 ++------- components/SideBar.js | 16 ++----- components/SideBarDrawer.js | 4 +- components/TopNav.js | 4 +- layouts/BaseLayout.js | 10 +++-- lib/notion/getNotionData.js | 54 ++++++++++++++++++++++-- pages/about.js | 31 ++++++++------ pages/archive/index.js | 71 +++++++++++++++---------------- pages/article/[slug].js | 77 +++++++++++++++++++++++----------- pages/category/[category].js | 34 +++++++-------- pages/category/index.js | 26 ++++++------ pages/index.js | 37 ++++++++++------ pages/page/[page].js | 47 ++++++++++++--------- pages/search.js | 57 ++++++++++++++----------- pages/tag/[tag].js | 27 ++++++------ pages/tag/index.js | 26 ++++++------ 19 files changed, 330 insertions(+), 276 deletions(-) diff --git a/components/BlogPostListPage.js b/components/BlogPostListPage.js index 3527bf21..0162bbd6 100644 --- a/components/BlogPostListPage.js +++ b/components/BlogPostListPage.js @@ -1,8 +1,6 @@ import BlogPostCard from '@/components/BlogPostCard' import PaginationNumber from './PaginationNumber' import BLOG from '@/blog.config' - -import { useRouter } from 'next/router' import BlogPostListEmpty from '@/components/BlogPostListEmpty' /** @@ -13,40 +11,20 @@ import BlogPostListEmpty from '@/components/BlogPostListEmpty' * @returns {JSX.Element} * @constructor */ -const BlogPostListPage = ({ page = 1, posts = [] }) => { - let filteredBlogPosts = posts +const BlogPostListPage = ({ page = 1, posts = [], postCount }) => { + const totalPage = Math.ceil(postCount / BLOG.postsPerPage) - // 处理查询过滤 支持标签、关键词过滤 - let currentSearch = '' - const router = useRouter() - if (router.query && router.query.s) { - currentSearch = router.query.s - filteredBlogPosts = posts.filter(post => { - const tagContent = post.tags ? post.tags.join(' ') : '' - const searchContent = post.title + post.summary + tagContent + post.slug - return searchContent.toLowerCase().includes(currentSearch.toLowerCase()) - }) - } - - // 处理分页 - const totalPage = Math.ceil(filteredBlogPosts.length / BLOG.postsPerPage) - const postsToShow = filteredBlogPosts.slice( - BLOG.postsPerPage * (page - 1), - BLOG.postsPerPage * page - ) - - if (!postsToShow || postsToShow.length === 0) { + if (!posts || posts.length === 0) { return } else { return (
{/* 文章列表 */}
- {postsToShow.map(post => ( + {posts.map(post => ( ))}
-
) diff --git a/components/LatestPostsGroup.js b/components/LatestPostsGroup.js index ffa832ab..76c20c62 100644 --- a/components/LatestPostsGroup.js +++ b/components/LatestPostsGroup.js @@ -1,5 +1,6 @@ import BLOG from '@/blog.config' -import { faFileAlt } from '@fortawesome/free-solid-svg-icons' +import { useGlobal } from '@/lib/global' +import { faArchive, faFileAlt } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import Link from 'next/link' import { useRouter } from 'next/router' @@ -10,25 +11,19 @@ import { useRouter } from 'next/router' * @param sliceCount 截取展示的数量 默认6 * @constructor */ -const LatestPostsGroup = ({ posts, sliceCount = 5 }) => { - // 深拷贝 - let postsSortByDate = Object.create(posts) - - // 时间排序 - postsSortByDate.sort((a, b) => { - const dateA = new Date(a?.lastEditedTime || a.createdTime) - const dateB = new Date(b?.lastEditedTime || b.createdTime) - return dateB - dateA - }) - - // 只取前五 - postsSortByDate = postsSortByDate.slice(0, sliceCount) - +const LatestPostsGroup = ({ posts }) => { + if (!posts) { + return <> + } // 获取当前路径 const currentPath = useRouter().asPath + const { locale } = useGlobal() - return <> - {postsSortByDate.map(post => { + return
+
+
{locale.COMMON.LATEST_POSTS}
+
+ {posts.map(post => { const selected = currentPath === `${BLOG.path}/article/${post.slug}` return ( @@ -42,6 +37,6 @@ const LatestPostsGroup = ({ posts, sliceCount = 5 }) => { ) })} - +
} export default LatestPostsGroup diff --git a/components/SideAreaLeft.js b/components/SideAreaLeft.js index 9ea4dda0..29351393 100644 --- a/components/SideAreaLeft.js +++ b/components/SideAreaLeft.js @@ -21,10 +21,9 @@ import Logo from './Logo' * @returns {JSX.Element} * @constructor */ -const SideAreaLeft = ({ title, tags, currentTag, post, posts, categories, currentCategory, currentSearch, targetRef }) => { +const SideAreaLeft = ({ title, tags, currentTag, post, postCount, categories, currentCategory, currentSearch, targetRef }) => { const { locale } = useGlobal() const showToc = post && post.toc && post.toc.length > 1 - const postCount = posts?.length || 0 return