summaryrefslogtreecommitdiff
path: root/layouts
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-06-28 12:20:37 +0800
committerEltrac <hi@guhub.cn>2025-06-28 12:20:37 +0800
commit6365da51e90dbbd69fa03e3399d9e29f335826f6 (patch)
tree3b5b86247b686a92448dad49a9cc1726c12c1320 /layouts
parentbe654acdc92a92b9564b654ae91778ab86b5cec7 (diff)
refactor: late-night time segment handling in chart
Former-commit-id: 63c5fb59b60397eac86d9a0c0b3175506c6c04e9
Diffstat (limited to 'layouts')
-rw-r--r--layouts/partials/components/publish-time-chart.html30
1 files 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 }}
-
<div class="time-chart-container">
<div class="time-chart-wrapper">
<div class="time-icon">☀️</div>
@@ -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 }}
- <div class="time-segment late-night"
- style="width: {{ printf "%.1f" $percentage }}%;"
- title="深夜: {{ $lateNightCount }}篇 ({{ printf "%.1f" $percentage }}%)">
- {{ if gt $percentage 8 }}深夜{{ end }}
- </div>
- {{ end }}
- {{ end }}
</div>
<div class="time-icon">🌙</div>
</div>
@@ -193,13 +177,5 @@
</div>
{{ end }}
{{ end }}
-
- {{ $lateNightCount := index $timeCounts "深夜" }}
- {{ if gt $lateNightCount 0 }}
- {{ $percentage := div (mul $lateNightCount 100.0) $total }}
- <div class="count-item" style="width: {{ printf "%.1f" $percentage }}%;">
- <span class="count-number">{{ $lateNightCount }}</span>
- </div>
- {{ end }}
</div>
</div>