From b83a498655b954384213b1ec02db8adc9eb0db3a Mon Sep 17 00:00:00 2001 From: Eltrac Date: Fri, 27 Jun 2025 20:08:34 +0800 Subject: feat: Add publish time distribution chart to stats page Introduced a new partial 'publish-time-chart.html' to visualize the distribution of article publish times across different time segments. --- layouts/_default/stats.html | 3 + .../partials/components/publish-time-chart.html | 205 +++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 layouts/partials/components/publish-time-chart.html diff --git a/layouts/_default/stats.html b/layouts/_default/stats.html index 8ca0cf47..f8eff423 100644 --- a/layouts/_default/stats.html +++ b/layouts/_default/stats.html @@ -120,6 +120,9 @@

每月文章字数

{{ partial "components/word-count-chart" . }} +

文章发布时间段分布

+
{{ partial "components/publish-time-chart" . }}
+
diff --git a/layouts/partials/components/publish-time-chart.html b/layouts/partials/components/publish-time-chart.html new file mode 100644 index 00000000..f6a534df --- /dev/null +++ b/layouts/partials/components/publish-time-chart.html @@ -0,0 +1,205 @@ + + +{{/* 定义时间段 */}} +{{ $fuzzyTimes := slice + (dict "limit" 5 "label" "凌晨" "class" "dawn") + (dict "limit" 7 "label" "清晨" "class" "early-morning") + (dict "limit" 11 "label" "早上" "class" "morning") + (dict "limit" 13 "label" "中午" "class" "noon") + (dict "limit" 17 "label" "下午" "class" "afternoon") + (dict "limit" 19 "label" "傍晚" "class" "evening") + (dict "limit" 22 "label" "晚上" "class" "night") +}} + +{{/* 初始化时间段计数 */}} +{{ $timeCounts := dict + "凌晨" 0 + "清晨" 0 + "早上" 0 + "中午" 0 + "下午" 0 + "傍晚" 0 + "晚上" 0 + "深夜" 0 +}} + +{{/* 统计每个时间段的文章数量 */}} +{{ range .Site.RegularPages }} + {{ if .Date }} + {{ $hour := .Date.Hour }} + {{ $fuzzyTime := "深夜" }} + {{ range $fuzzyTimes }} + {{ if lt $hour .limit }} + {{ $fuzzyTime = .label }} + {{ break }} + {{ end }} + {{ end }} + {{ $currentCount := index $timeCounts $fuzzyTime }} + {{ $timeCounts = merge $timeCounts (dict $fuzzyTime (add $currentCount 1)) }} + {{ end }} +{{ end }} + +{{/* 计算总数 */}} +{{ $total := 0 }} +{{ range $timeCounts }} + {{ $total = add $total . }} +{{ end }} + +
+
+
🌙
+
+ {{ range $fuzzyTimes }} + {{ $count := index $timeCounts .label }} + {{ if gt $total 0 }} + {{ $percentage := div (mul $count 100.0) $total }} + {{ if gt $count 0 }} +
+ {{ if gt $percentage 8 }}{{ .label }}{{ end }} +
+ {{ end }} + {{ end }} + {{ end }} + + {{/* 深夜时间段 */}} + {{ $lateNightCount := index $timeCounts "深夜" }} + {{ if gt $total 0 }} + {{ $percentage := div (mul $lateNightCount 100.0) $total }} + {{ if gt $lateNightCount 0 }} +
+ {{ if gt $percentage 8 }}深夜{{ end }} +
+ {{ end }} + {{ end }} +
+
☀️
+
+ +
+ {{ range $fuzzyTimes }} + {{ $count := index $timeCounts .label }} + {{ if gt $count 0 }} + {{ $percentage := div (mul $count 100.0) $total }} +
+ {{ $count }} +
+ {{ end }} + {{ end }} + + {{ $lateNightCount := index $timeCounts "深夜" }} + {{ if gt $lateNightCount 0 }} + {{ $percentage := div (mul $lateNightCount 100.0) $total }} +
+ {{ $lateNightCount }} +
+ {{ end }} +
+
\ No newline at end of file -- cgit v1.2.3