From 845be8a6fe095021e9fd260cff2b1396e23d5ee0 Mon Sep 17 00:00:00 2001 From: gbanyan Date: Mon, 17 Nov 2025 21:31:39 +0800 Subject: [PATCH] Limit sidebar to top 5 popular tags and add tag index page --- app/tags/page.tsx | 46 ++++++++++++++++++++++++++++++++++++ components/right-sidebar.tsx | 12 ++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 app/tags/page.tsx diff --git a/app/tags/page.tsx b/app/tags/page.tsx new file mode 100644 index 0000000..079f878 --- /dev/null +++ b/app/tags/page.tsx @@ -0,0 +1,46 @@ +import Link from 'next/link'; +import type { Metadata } from 'next'; +import { getAllTagsWithCount } from '@/lib/posts'; + +export const metadata: Metadata = { + title: '標籤索引' +}; + +export default function TagIndexPage() { + const tags = getAllTagsWithCount(); + + const colorClasses = [ + 'bg-rose-100 text-rose-700 dark:bg-rose-900/60 dark:text-rose-200', + 'bg-emerald-100 text-emerald-700 dark:bg-emerald-900/60 dark:text-emerald-200', + 'bg-sky-100 text-sky-700 dark:bg-sky-900/60 dark:text-sky-200', + 'bg-amber-100 text-amber-700 dark:bg-amber-900/60 dark:text-amber-200', + 'bg-violet-100 text-violet-700 dark:bg-violet-900/60 dark:text-violet-200' + ]; + + return ( +
+

+ 標籤索引 +

+

+ 目前共有 {tags.length} 個標籤。 +

+
+ {tags.map(({ tag, slug, count }, index) => { + const color = colorClasses[index % colorClasses.length]; + return ( + + {tag} + ({count}) + + ); + })} +
+
+ ); +} + diff --git a/components/right-sidebar.tsx b/components/right-sidebar.tsx index e245f3c..4def051 100644 --- a/components/right-sidebar.tsx +++ b/components/right-sidebar.tsx @@ -4,7 +4,7 @@ import { getAllPostsSorted, getAllTagsWithCount } from '@/lib/posts'; export function RightSidebar() { const latest = getAllPostsSorted().slice(0, 5); - const tags = getAllTagsWithCount().slice(0, 30); + const tags = getAllTagsWithCount().slice(0, 5); return (