summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2024-12-01 22:58:31 +0800
committerEltrac <hi@guhub.cn>2024-12-01 22:58:31 +0800
commit473ebc56c3566ac895725ffab0d9e24f452b993d (patch)
tree0ee9473701cad4000ebab4c6c3c68cd7d0b50246
parent3416a057ff68d4bdba8d122889fc2c37df989514 (diff)
feat: article word count for cal heatmap
-rw-r--r--hugo.toml8
-rw-r--r--themes/yinyang/layouts/index.calheatmap.json15
2 files changed, 23 insertions, 0 deletions
diff --git a/hugo.toml b/hugo.toml
index 91d5888f..f9e2fd5a 100644
--- a/hugo.toml
+++ b/hugo.toml
@@ -39,3 +39,11 @@ target = "_blank"
[services.rss]
limit = 10
+[outputs]
+ home = ["HTML", "calheatmap"]
+
+[outputFormats]
+[outputFormats.calheatmap]
+ mediaType = "application/json"
+ baseName = "cal-heatmap"
+ isPlainText = true
diff --git a/themes/yinyang/layouts/index.calheatmap.json b/themes/yinyang/layouts/index.calheatmap.json
new file mode 100644
index 00000000..65b1d942
--- /dev/null
+++ b/themes/yinyang/layouts/index.calheatmap.json
@@ -0,0 +1,15 @@
+{{- /* 设置 Content-Type 为 JSON */ -}}
+{{- $entries := slice -}}
+{{- range .Site.RegularPages -}}
+ {{- $wordCount := .WordCount -}}
+ {{- $date := .Date.Format "2006-01-02" -}}
+ {{- $entry := dict "date" $date "value" $wordCount -}}
+ {{- $entries = $entries | append $entry -}}
+{{- end -}}
+{{- $.Scratch.Add "results" $entries -}}
+[
+ {{- range $i, $entry := $.Scratch.Get "results" -}}
+ {{- if $i }},{{ end -}}
+ {{- $entry | jsonify -}}
+ {{- end -}}
+]