From ed0aa02c267c554b78e527cc8ed0f461b09db81a Mon Sep 17 00:00:00 2001 From: KazooTTT Date: Thu, 25 Jul 2024 13:58:00 +0800 Subject: [PATCH] fix: replace tag with category in the category page --- .../categories/[category]/[...page].astro | 26 ++++++++++--------- src/pages/categories/index.astro | 8 +++--- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/pages/categories/[category]/[...page].astro b/src/pages/categories/[category]/[...page].astro index 4971476..b00fb4f 100644 --- a/src/pages/categories/[category]/[...page].astro +++ b/src/pages/categories/[category]/[...page].astro @@ -8,18 +8,20 @@ import Pagination from '@/components/Paginator.astro' import PostPreview from '@/components/blog/PostPreview.astro' import PageLayout from '@/layouts/BaseLayout.astro' import Button from '@/components/Button.astro' -import { getAllPosts, getUniqueTags, sortMDByDate } from '@/utils' +import { getAllPosts, getUniqueCategories, sortMDByDate } from '@/utils' export const getStaticPaths: GetStaticPaths = async ({ paginate }) => { const allPosts = await getAllPosts() const allPostsByDate = sortMDByDate(allPosts) - const uniqueTags = getUniqueTags(allPostsByDate) + const uniqueCategories = getUniqueCategories(allPostsByDate) - return uniqueTags.flatMap((tag) => { - const filterPosts = allPostsByDate.filter((post) => post.data.tags.includes(tag)) + return uniqueCategories.flatMap((category) => { + const filterPosts = allPostsByDate.filter((post) => + category === '未分类' ? !post.data.category : post.data.category === category + ) return paginate(filterPosts, { pageSize: 10, - params: { tag } + params: { category } }) }) } @@ -29,23 +31,23 @@ interface Props { } const { page } = Astro.props -const { tag } = Astro.params +const { Category } = Astro.params const meta = { - description: `View all posts with the tag - ${tag}`, - title: `Tag: ${tag}` + description: `View all posts of Category - ${Category}`, + title: `Category: ${Category}` } const paginationProps = { ...(page.url.prev && { prevUrl: { - text: `← Previous Tags`, + text: `← Previous Category`, url: page.url.prev } }), ...(page.url.next && { nextUrl: { - text: `Next Tags →`, + text: `Next Category →`, url: page.url.next } }) @@ -70,8 +72,8 @@ const paginationProps = {

- Tags: - #{tag} + Category: + #{Category}