···11+{{/* Renders a visits counter for the current page using data/plausible-stats/visits.json */}}
22+{{ $visits := 0 }}
33+{{ $data := index .Site.Data "plausible-stats" }}
44+{{ if $data }}
55+ {{ $pages := $data.visits }}
66+ {{ if $pages }}
77+ {{ $rel := .RelPermalink }}
88+ {{/* Data contains decoded UTF-8 paths. Normalize data side by encoding with urlize, then compare to the raw RelPermalink. */}}
99+ {{/* Try exact match against raw permalink first */}}
1010+ {{ $candidate1 := $rel }}
1111+ {{/* Also try without leading language prefix like /fr or /en */}}
1212+ {{ $candidate2 := replaceRE "^/(fr|en)" "" $candidate1 }}
1313+ {{/* Build a temporary slice of pages where we compare urlized data paths to the permalink */}}
1414+ {{ $encodedPages := slice }}
1515+ {{ range $pages }}
1616+ {{ $p := .page }}
1717+ {{ $pUrlized := urlize $p }}
1818+ {{ $encodedPages = $encodedPages | append (dict "page" $pUrlized "visits" .visits) }}
1919+ {{ end }}
2020+ {{ $match := where $encodedPages "page" $candidate1 }}
2121+ {{ if not (gt (len $match) 0) }}
2222+ {{ $match = where $encodedPages "page" $candidate2 }}
2323+ {{ end }}
2424+ {{ with index $match 0 }}
2525+ {{ $visits = .visits }}
2626+ {{ end }}
2727+ {{ end }}
2828+{{ end }}
2929+3030+{{ if gt $visits 0 }}
3131+ - <span class="visits-counter" title="Page views">👀 {{ $visits }}</span>
3232+{{ end }}