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