From 6365da51e90dbbd69fa03e3399d9e29f335826f6 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Sat, 28 Jun 2025 12:20:37 +0800 Subject: refactor: late-night time segment handling in chart Former-commit-id: 63c5fb59b60397eac86d9a0c0b3175506c6c04e9 --- .../partials/components/publish-time-chart.html | 30 +++------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/layouts/partials/components/publish-time-chart.html b/layouts/partials/components/publish-time-chart.html index 45de208c..dac9e542 100644 --- a/layouts/partials/components/publish-time-chart.html +++ b/layouts/partials/components/publish-time-chart.html @@ -113,6 +113,7 @@ (dict "limit" 17 "label" "下午" "class" "afternoon") (dict "limit" 19 "label" "傍晚" "class" "evening") (dict "limit" 22 "label" "晚上" "class" "night") + (dict "limit" 24 "label" "深夜" "class" "late-night") }} {{/* 初始化时间段计数 */}} @@ -128,6 +129,7 @@ }} {{/* 统计每个时间段的文章数量 */}} +{{ $total := 0 }} {{ range .Site.RegularPages }} {{ if .Date }} {{ $hour := .Date.Hour }} @@ -138,17 +140,12 @@ {{ break }} {{ end }} {{ end }} + {{ $total = add $total 1 }} {{ $currentCount := index $timeCounts $fuzzyTime }} {{ $timeCounts = merge $timeCounts (dict $fuzzyTime (add $currentCount 1)) }} {{ end }} {{ end }} -{{/* 计算总数 */}} -{{ $total := 0 }} -{{ range $timeCounts }} - {{ $total = add $total . }} -{{ end }} -
☀️
@@ -166,19 +163,6 @@ {{ 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 }}
🌙
@@ -193,13 +177,5 @@ {{ end }} {{ end }} - - {{ $lateNightCount := index $timeCounts "深夜" }} - {{ if gt $lateNightCount 0 }} - {{ $percentage := div (mul $lateNightCount 100.0) $total }} -
- {{ $lateNightCount }} -
- {{ end }} -- cgit v1.2.3