Source code of my website
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

✨ : add visits counter for posts using plausible data

+33
+1
layouts/partials/post/info.html
··· 20 20 <span class="reading-time"> 21 21 <span>{{ i18n "readingTime" .ReadingTime }}</span> 22 22 </span> 23 + {{ partial "post/visits.html" . }} 23 24 </div> 24 25 25 26 {{ with .GetTerms "tags" }}
+32
layouts/partials/post/visits.html
··· 1 + {{/* Renders a visits counter for the current page using data/plausible-stats/visits.json */}} 2 + {{ $visits := 0 }} 3 + {{ $data := index .Site.Data "plausible-stats" }} 4 + {{ if $data }} 5 + {{ $pages := $data.visits }} 6 + {{ if $pages }} 7 + {{ $rel := .RelPermalink }} 8 + {{/* Data contains decoded UTF-8 paths. Normalize data side by encoding with urlize, then compare to the raw RelPermalink. */}} 9 + {{/* Try exact match against raw permalink first */}} 10 + {{ $candidate1 := $rel }} 11 + {{/* Also try without leading language prefix like /fr or /en */}} 12 + {{ $candidate2 := replaceRE "^/(fr|en)" "" $candidate1 }} 13 + {{/* Build a temporary slice of pages where we compare urlized data paths to the permalink */}} 14 + {{ $encodedPages := slice }} 15 + {{ range $pages }} 16 + {{ $p := .page }} 17 + {{ $pUrlized := urlize $p }} 18 + {{ $encodedPages = $encodedPages | append (dict "page" $pUrlized "visits" .visits) }} 19 + {{ end }} 20 + {{ $match := where $encodedPages "page" $candidate1 }} 21 + {{ if not (gt (len $match) 0) }} 22 + {{ $match = where $encodedPages "page" $candidate2 }} 23 + {{ end }} 24 + {{ with index $match 0 }} 25 + {{ $visits = .visits }} 26 + {{ end }} 27 + {{ end }} 28 + {{ end }} 29 + 30 + {{ if gt $visits 0 }} 31 + - <span class="visits-counter" title="Page views">👀 {{ $visits }}</span> 32 + {{ end }}