diff --git a/components/BlogPostArchive.js b/components/BlogPostArchive.js new file mode 100644 index 00000000..c37b2722 --- /dev/null +++ b/components/BlogPostArchive.js @@ -0,0 +1,46 @@ +import React, { useRef } from 'react' +import Link from 'next/link' +import BLOG from '@/blog.config' +/** + * 博客归档列表 + * @param posts 所有文章 + * @param archiveTitle 归档标题 + * @returns {JSX.Element} + * @constructor + */ +const BlogPostArchive = ({ posts = [], archiveTitle }) => { + const targetRef = useRef(null) + if (!posts || posts.length === 0) { + return <> + } else { + return
+
{archiveTitle}
+ {/* 文章列表 */} + + +
+ } +} + +/** + * 获取从第1页到指定页码的文章 + * @param page 第几页 + * @param totalPosts 所有文章 + * @param postsPerPage 每页文章数量 + * @returns {*} + */ +const getPostByPage = function (page, totalPosts, postsPerPage) { + return totalPosts.slice( + 0, + postsPerPage * page + ) +} +export default BlogPostArchive diff --git a/components/BlogPostCardMini.js b/components/BlogPostCardMini.js deleted file mode 100644 index bb87d885..00000000 --- a/components/BlogPostCardMini.js +++ /dev/null @@ -1,25 +0,0 @@ -import BLOG from '@/blog.config' -import Link from 'next/link' - -const BlogPostCardMini = ({ post }) => { - return ( - -
- {/* 封面图 */} - {post.page_cover && post.page_cover.length > 1 && ( - {post.title} - )} - -
-
- {post.title} -
-

{post.summary}

-
-
- - ) -} - -export default BlogPostCardMini diff --git a/components/SideBar.js b/components/SideBar.js index af1eee4a..bfb232d3 100644 --- a/components/SideBar.js +++ b/components/SideBar.js @@ -61,7 +61,7 @@ const SideBar = ({ tags, currentTag, post, posts, categories, currentCategory, c
{locale.COMMON.LATEST_POSTS}
- +
{locale.COMMON.MORE}
diff --git a/lib/lang/en-US.js b/lib/lang/en-US.js index d8fdfca8..f9d619bc 100644 --- a/lib/lang/en-US.js +++ b/lib/lang/en-US.js @@ -4,7 +4,8 @@ export default { RSS: 'RSS', SEARCH: 'Search', ABOUT: 'About', - MAIL: 'E-Mail' + MAIL: 'E-Mail', + ARCHIVE: 'Archive' }, COMMON: { MORE: 'More', diff --git a/lib/lang/zh-CN.js b/lib/lang/zh-CN.js index 6a6b11cd..33445f81 100644 --- a/lib/lang/zh-CN.js +++ b/lib/lang/zh-CN.js @@ -5,7 +5,8 @@ export default { SEARCH: '搜索', ABOUT: '关于', NAVIGATOR: '导航', - MAIL: '邮箱' + MAIL: '邮箱', + ARCHIVE: '归档' }, COMMON: { MORE: '更多', diff --git a/pages/blogs/index.js b/pages/archive/index.js similarity index 60% rename from pages/blogs/index.js rename to pages/archive/index.js index f8278b00..ddfa1b54 100644 --- a/pages/blogs/index.js +++ b/pages/archive/index.js @@ -6,6 +6,7 @@ import { getNotionPageData } from '@/lib/notion/getNotionData' import StickyBar from '@/components/StickyBar' import React from 'react' import { useGlobal } from '@/lib/global' +import BlogPostArchive from '@/components/BlogPostArchive' export async function getStaticProps () { const from = 'index' @@ -31,24 +32,39 @@ const Index = ({ allPosts, tags, categories }) => { // 时间排序 postsSortByDate.sort((a, b) => { - const dateA = new Date(a?.lastEditedTime || a.createdTime) - const dateB = new Date(b?.lastEditedTime || b.createdTime) + const dateA = new Date(a?.date.start_date || a.createdTime) + const dateB = new Date(b?.date.start_date || b.createdTime) return dateB - dateA }) const meta = { - title: `${BLOG.title} | ${locale.COMMON.LATEST_POSTS} `, + title: `${BLOG.title} | ${locale.NAV.ARCHIVE} `, description: BLOG.description, type: 'website' } + const archivePosts = { } + + postsSortByDate.forEach(post => { + const date = post.date.start_date.slice(0, 7) + if (archivePosts[date]) { + archivePosts[date].push(post) + } else { + archivePosts[date] = [post] + } + }) + return ( -
+
-
{locale.COMMON.LATEST_POSTS}
+
{locale.NAV.ARCHIVE}
- +
+ {Object.keys(archivePosts).map(archiveTitle => ( + + ))} +
)