From 80bae4b2a9e21bff848fdeee6768ff98ee284aa8 Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Sun, 29 May 2022 14:23:59 -0400 Subject: [PATCH] Added stats layout --- layouts/_default/single.html | 2 +- layouts/_default/stats.html | 113 +++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 layouts/_default/stats.html diff --git a/layouts/_default/single.html b/layouts/_default/single.html index c7ce0bd..1c3a4c4 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -1,4 +1,4 @@ -{{ define "main"}} +{{ define "main" }} {{ partial "header.html" . }}
{{ partial "date.html" . }} diff --git a/layouts/_default/stats.html b/layouts/_default/stats.html new file mode 100644 index 0000000..d275e95 --- /dev/null +++ b/layouts/_default/stats.html @@ -0,0 +1,113 @@ +{{ define "main" }} + +{{ partial "header.html" . }} +
+
+
+ {{ .Content }} + {{ $posts := where site.RegularPages "Type" "blog" }} + + {{ $postCount := len $posts }} + + {{ $scratch := newScratch }} + {{ $scratch.Set "longCount" 0 }} + {{ $scratch.Set "shortCount" 9999999999 }} + {{ range $posts }} + + {{ $scratch.Add "wordcount" .WordCount }} + + {{ if ge .WordCount ($scratch.Get "longCount") }} + {{ $scratch.Set "longestPost" . }} + {{ $scratch.Set "longCount" .WordCount }} + {{ end }} + + {{ if le .WordCount ($scratch.Get "shortCount") }} + {{ $scratch.Set "shortestPost" . }} + {{ $scratch.Set "shortCount" .WordCount }} + {{ end }} + {{ end }} + + {{ $wordCount := $scratch.Get "wordcount" }} + {{ $avgPostLength := div $wordCount $postCount }} + + + + + + + + + + + + + + + + + + + + + +
Total Posts Published{{ $postCount | lang.NumFmt 0 }}
Total Words Written{{ $wordCount | lang.NumFmt 0 }}
Average Words per Post{{ $avgPostLength | lang.NumFmt 0 }}
Longest Post Published + {{ with $scratch.Get "longestPost" }} + {{ .Title }} with {{ .WordCount }} words + {{ end }} +
Shortest Post Published + {{ with $scratch.Get "shortestPost" }} + {{ .Title }} with {{ .WordCount }} words + {{ end }} +
+ + {{ $grouped := $posts.GroupByDate "2006" }} + +

Posts Per Year

+ +
+ + +
+ + + + {{ $chartPre := "{type: 'line',data: {labels: [" }} + {{ $chartYearKeys := trim ($scratch.Get "yearKeys") ","}} + {{ $chartYearCount := trim ($scratch.Get "yearCount") ","}} + {{ $chartMid := "],datasets: [{label: 'Posts Published',data: [" }} + {{ $chartPost := "],backgroundColor: 'rgb(54, 128, 56)',borderColor: 'rgb(54, 128, 56)',borderWidth: 3}]},options: {maintainAspectRatio: false, animation: false, scales: {y: {ticks: {beginAtZero: true}}}}}" + }} + + + {{ $chartData := printf "%s" $chartPost | printf "%s%s" $chartYearCount | printf "%s%s" $chartMid | printf "%s%s" $chartYearKeys | printf "%s%s" $chartPre | printf "%s" }} + + + +
+
+
+{{ partial "footer.html" . }} +{{ end }}