From f7c7cbb24c0a46ff5efb1c1a73d643147598b08c Mon Sep 17 00:00:00 2001 From: MeiK Date: Sat, 9 May 2020 13:21:42 +0800 Subject: [PATCH] Add contributions graph --- layouts/partials/overview.html | 129 ++++++++++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 1 deletion(-) diff --git a/layouts/partials/overview.html b/layouts/partials/overview.html index 2283e3e..0eb9cb4 100644 --- a/layouts/partials/overview.html +++ b/layouts/partials/overview.html @@ -55,7 +55,134 @@ + {{ if eq .Site.Params.contributions "post" }} +
+
+
+

+ {{ $scratch := newScratch }} + {{ if eq now.Weekday.String "Monday" }} + {{ $scratch.Set "dayOfWeek" 1 }} + {{ else if eq now.Weekday.String "Tuesday" }} + {{ $scratch.Set "dayOfWeek" 2 }} + {{ else if eq now.Weekday.String "Wednesday" }} + {{ $scratch.Set "dayOfWeek" 3 }} + {{ else if eq now.Weekday.String "Thursday" }} + {{ $scratch.Set "dayOfWeek" 4 }} + {{ else if eq now.Weekday.String "Friday" }} + {{ $scratch.Set "dayOfWeek" 5 }} + {{ else if eq now.Weekday.String "Saturday" }} + {{ $scratch.Set "dayOfWeek" 6 }} + {{ else if eq now.Weekday.String "Sunday" }} + {{ $scratch.Set "dayOfWeek" 7 }} + {{ end }} + {{ $dayOfWeek := $scratch.Get "dayOfWeek" }} + + {{ $allDays := add 364 $dayOfWeek }} + {{ $startDate := (time (now.Format "2006-01-02")).AddDate 0 0 (int (sub 0 $allDays)) }} + {{ $startMonth := 0 }} + {{ $monthPos := slice }} + {{ $weeks := 53 }} + {{ $count := 0 }} + + {{ $mainSections := .Site.Params.mainSections | default (slice "post") }} + {{ $section := where .Site.RegularPages "Section" "in" $mainSections }} + + {{ range $section }} + {{ $scratch.Add (.PublishDate.Format "2006-01-02") 1 }} + {{ if le $startDate .PublishDate }} + {{ $count = add $count 1 }} + {{ end }} + {{ end }} + {{ $count }} contributions in the last year +

+
+ +
+
+
+ + + + {{ range $i, $sequence := (seq $weeks) }} + + {{ range $j, $seq := (seq 7) }} + + {{ $date := $startDate.AddDate 0 0 (int (add (mul $i 7) $j)) }} + {{ $color := newScratch }} + + {{ if eq $j 0 }} + {{ if ne $startMonth $date.Month }} + {{ $monthPos = $monthPos | append $i}} + {{ $startMonth = $date.Month }} + {{ end }} + {{ end }} + + {{ $dateCount := $scratch.Get ($date.Format "2006-01-02") }} + {{ if eq $dateCount nil }} + {{ $dateCount = 0 }} + {{ end }} + + {{ if eq $dateCount 0 }} + {{ $color.Set "color" "#ebedf0" }} + {{ else if eq $dateCount 1 }} + {{ $color.Set "color" "#c6e48b" }} + {{ else if eq $dateCount 2 }} + {{ $color.Set "color" "#7bc96f" }} + {{ else if eq $dateCount 3 }} + {{ $color.Set "color" "#239a3b" }} + {{ else }} + {{ $color.Set "color" "#196127" }} + {{ end }} + + {{ end }} + + {{ end }} + {{ range $index, $element := first 12 $monthPos }} + {{ (now.AddDate 0 $index 0).Format "Jan" }} + {{ end }} + + Mon + + Wed + + Fri + + + + + +
+ +
+
+
+
+ {{ end }}
- + \ No newline at end of file