blob: 3fa35078c3c4f4e1ae57133313acc7e76ab9cb5c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
{{/* 定义时间段 */}}
{{ $fuzzyTimes := slice
(dict "limit" 5 "label" "凌晨" "class" "dawn")
(dict "limit" 11 "label" "早上" "class" "morning")
(dict "limit" 13 "label" "中午" "class" "noon")
(dict "limit" 17 "label" "下午" "class" "afternoon")
(dict "limit" 22 "label" "晚上" "class" "night")
(dict "limit" 24 "label" "深夜" "class" "late-night")
}}
{{/* 初始化时间段计数 */}}
{{ $timeCounts := dict
"凌晨" 0
"清晨" 0
"早上" 0
"中午" 0
"下午" 0
"傍晚" 0
"晚上" 0
"深夜" 0
}}
{{/* 统计每个时间段的文章数量 */}}
{{ $total := 0 }}
{{ range .Site.RegularPages }}
{{ if .Date }}
{{ $hour := .Date.Hour }}
{{ $fuzzyTime := "深夜" }}
{{ range $fuzzyTimes }}
{{ if lt $hour .limit }}
{{ $fuzzyTime = .label }}
{{ break }}
{{ end }}
{{ end }}
{{ $total = add $total 1 }}
{{ $currentCount := index $timeCounts $fuzzyTime }}
{{ $timeCounts = merge $timeCounts (dict $fuzzyTime (add $currentCount 1)) }}
{{ end }}
{{ end }}
<div class="w-full max-w-[700px] my-4">
<div class="flex items-center gap-4 mb-4">
<div class="text-size-2xl flex-shrink-0">☀️</div>
<div class="flex gap-2 w-full h-6 dark:invert">
{{ range $fuzzyTimes }}
{{ $count := index $timeCounts .label }}
{{ if gt $total 0 }}
{{ $percentage := div (mul $count 100.0) $total }}
{{ if gt $count 0 }}
<div class="flex items-center justify-center
text-white rounded-2xl text-size-sm font-500 relative
bg-black opacity-{{ add (mul (int (div $percentage 10)) 10) 30 }}
{{ .class }}"
style="width: {{ printf "%.1f" $percentage }}%;"
title="{{ .label }}: {{ $count }}篇 ({{ printf "%.1f" $percentage }}%)">
{{ if gt $percentage 8 }}{{ .label }}{{ end }}
</div>
{{ end }}
{{ end }}
{{ end }}
</div>
<div class="text-size-2xl flex-shrink-0">🌙</div>
</div>
<div class="flex gap-2 mt-2 px-10">
{{ range $fuzzyTimes }}
{{ $count := index $timeCounts .label }}
{{ if gt $count 0 }}
{{ $percentage := div (mul $count 100.0) $total }}
<div class="flex flex-col items-center text-size-xs
text-secondary font-mono"
style="width: {{ printf "%.1f" $percentage }}%;">
<span class="font-600 text-[var(--primary-text-color)]">{{ $count }}</span>
</div>
{{ end }}
{{ end }}
</div>
</div>
|