diff --git a/src/components/StatsChart.astro b/src/components/StatsChart.astro index 23b544e..08ef5ec 100644 --- a/src/components/StatsChart.astro +++ b/src/components/StatsChart.astro @@ -10,9 +10,11 @@ interface Props { subtitle?: string; type: 'pie' | 'line'; items: ChartItem[]; + totalLabel?: string; + valueLabel?: string; } -const { title, subtitle, type, items } = Astro.props; +const { title, subtitle, type, items, totalLabel = '篇文章', valueLabel = '篇' } = Astro.props; const colors = ['#3eb8be', '#f2a65a', '#7f9cf5', '#68b684', '#f07f7f', '#b18ce8', '#e0b34f', '#5ca4d3']; const safeItems = items.filter((item) => item.value > 0); const total = safeItems.reduce((sum, item) => sum + item.value, 0); @@ -74,7 +76,7 @@ const labelStep = Math.max(1, Math.ceil(linePoints.length / 6)); > ))} {total} - 篇文章 + {totalLabel}
@@ -124,7 +126,7 @@ const labelStep = Math.max(1, Math.ceil(linePoints.length / 6)); {linePoints.map((point, index) => ( <> - {`${point.label}: ${point.value} 篇`} + {`${point.label}: ${point.value} ${valueLabel}`} {index % labelStep === 0 && ( {point.label} diff --git a/src/pages/categories/index.astro b/src/pages/categories/index.astro index 27513a2..7221664 100644 --- a/src/pages/categories/index.astro +++ b/src/pages/categories/index.astro @@ -11,12 +11,30 @@ const categoryStats = categories.map((category) => ({ value: posts.filter((post) => post.categories.includes(category)).length, href: getCategoryHref(category), })); +const uncategorizedCount = posts.filter((post) => post.categories.length === 0).length; +const multiCategoryCount = posts.filter((post) => post.categories.length > 1).length; +const categoryArchiveCount = categoryStats.reduce((sum, category) => sum + category.value, 0) + uncategorizedCount; +const categoryChartStats = [ + ...categoryStats, + { + label: '未分类', + value: uncategorizedCount, + }, +]; +const categoryChartSubtitle = [ + `${posts.length} 篇文章`, + `${categoryArchiveCount} 次归档`, + multiCategoryCount ? `${multiCategoryCount} 篇多分类` : null, + uncategorizedCount ? `${uncategorizedCount} 篇未分类` : null, +] + .filter(Boolean) + .join(' · '); ---
- +