{{/* 定义时间段 */}} {{ $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 }}
☀️
{{ 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 }}
🌙
{{ range $fuzzyTimes }} {{ $count := index $timeCounts .label }} {{ if gt $count 0 }} {{ $percentage := div (mul $count 100.0) $total }}
{{ $count }}
{{ end }} {{ end }}