From 32d6c382346ef72662d3f99a0ed1c1ef9a8d05e1 Mon Sep 17 00:00:00 2001 From: QIU Date: Tue, 26 Aug 2025 06:23:48 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E6=A0=87=E7=AD=BE=E9=A1=B5=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=B3=BB=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/SeriesPanel.astro | 109 +++++++++++++++++++++++++++++++ src/config.ts | 1 + src/constants/link-presets.ts | 7 ++ src/pages/series.astro | 10 +++ src/types/config.ts | 3 +- 5 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 src/components/SeriesPanel.astro create mode 100644 src/pages/series.astro diff --git a/src/components/SeriesPanel.astro b/src/components/SeriesPanel.astro new file mode 100644 index 0000000..1dee837 --- /dev/null +++ b/src/components/SeriesPanel.astro @@ -0,0 +1,109 @@ +--- +import { UNCATEGORIZED } from '@constants/constants' +import I18nKey from '../i18n/i18nKey' +import { i18n } from '../i18n/translation' +import { getSortedPosts } from '../utils/content-utils' +import { getPostUrlBySlug } from '../utils/url-utils' +import { getCategoryUrl } from '../utils/url-utils' + +interface Props { + keyword?: string + tags?: string[] + categories?: string[] +} + +let posts = await getSortedPosts() + +interface Series { + count: number + name: string + posts: typeof posts +} + +const groups: { category: string; series: Series[] }[] = (() => { + const groupedSeries = posts.reduce( + (grouped: { [category: string]: {[seriesName: string]: Series} }, post) => { + const category = post.data.category || UNCATEGORIZED + const series = post.data.series || UNCATEGORIZED + if (category == UNCATEGORIZED || series === UNCATEGORIZED) { + return grouped + } + if (!grouped[category]) { + grouped[category] = {} + } + if (!grouped[category][series]) { + grouped[category][series] = { + count: 0, + name: series, + posts: [], + } + } + grouped[category][series].count++ + grouped[category][series].posts.push(post) + return grouped + }, + {}, + ) + + // convert the object to an array + const groupedSeriesArray = Object.keys(groupedSeries).map(key => ({ + category: key, + series: Object.values(groupedSeries[key]), + })) + + return groupedSeriesArray +})() +--- + +
+ { + groups.map(group => ( +
+
+ +
+
+
+
{group.series.length} 个{i18n(I18nKey.series)}
+
+ {group.series.map(series => ( + +
+ +
+ { series.count } 篇文章 +
+ +
+
+
+ +
+ {series.name} +
+
+
+ ))} +
+ )) + } +
\ No newline at end of file diff --git a/src/config.ts b/src/config.ts index d48354a..8032408 100644 --- a/src/config.ts +++ b/src/config.ts @@ -44,6 +44,7 @@ export const navBarConfig: NavBarConfig = { links: [ LinkPreset.Home, LinkPreset.Archive, + LinkPreset.Series, LinkPreset.About, { name: "GitHub", diff --git a/src/constants/link-presets.ts b/src/constants/link-presets.ts index bb7db5d..662ab3c 100644 --- a/src/constants/link-presets.ts +++ b/src/constants/link-presets.ts @@ -15,4 +15,11 @@ export const LinkPresets: { [key in LinkPreset]: NavBarLink } = { name: i18n(I18nKey.archive), url: "/archive/", }, + [LinkPreset.Series]: { + + name: i18n(I18nKey.series), + + url: '/series/', + + }, }; diff --git a/src/pages/series.astro b/src/pages/series.astro new file mode 100644 index 0000000..6a99dce --- /dev/null +++ b/src/pages/series.astro @@ -0,0 +1,10 @@ +--- +import MainGridLayout from '@layouts/MainGridLayout.astro' +import SeriesPanel from '@components/SeriesPanel.astro' +import { i18n } from '@i18n/translation' +import I18nKey from '@i18n/i18nKey' +--- + + + + \ No newline at end of file diff --git a/src/types/config.ts b/src/types/config.ts index e1fe5e1..6c231ee 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -47,7 +47,8 @@ export type Favicon = { export enum LinkPreset { Home = 0, Archive = 1, - About = 2, + Series = 2, + About = 3, } export type NavBarLink = {