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 = {