fixed view like counters to work across multiple langs

This commit is contained in:
Nuno Coração 2024-03-20 16:05:48 +00:00
parent 74b985654e
commit 6190898b70
6 changed files with 48 additions and 14 deletions

View file

@ -1,7 +1,9 @@
var liked_page = false
var id = oid ? oid.replaceAll("/", "-") : oid
var id_likes = oid_likes ? oid_likes.replaceAll("/", "-") : oid_likes
if (typeof auth !== 'undefined') {
var id = oid ? oid.replaceAll("/", "-") : oid
var viewed = localStorage.getItem(id);
if (!viewed) {
@ -28,7 +30,6 @@ if (typeof auth !== 'undefined') {
});
}
var id_likes = oid_likes ? oid_likes.replaceAll("/", "-") : oid_likes
var liked = localStorage.getItem(id_likes);
if (liked) {
@ -97,7 +98,6 @@ function remove_like_article(id_likes) {
}
function process_article() {
var id_likes = oid_likes ? oid_likes.replaceAll("/", "-") : oid_likes
if (!liked_page) {
like_article(id_likes)
} else {

View file

@ -0,0 +1,17 @@
---
title: "Documentation"
description: "Learn how to use Blowfish and its features."
cascade:
showDate: false
showAuthor: false
invertPagination: true
---
{{< lead >}}
Simple, yet powerful. Learn how to use Blowfish and its features.
{{< /lead >}}
This section contains everything you need to know about Blowfish. If you're new, check out the [Installation]({{< ref "docs/installation" >}}) guide to begin or visit the [Samples]({{< ref "samples" >}}) section to see what Blowfish can do.
---

View file

@ -19,12 +19,16 @@
<div class="mt-1 mb-2 text-base text-neutral-500 dark:text-neutral-400 print:hidden">
{{ partial "article-meta/list.html" (dict "context" . "scope" "single") }}
</div>
{{ with .File }}
{{ $path := .File.Path }}
{{range .AllTranslations}}
{{ $lang := print "." .Lang ".md" }}
{{ $path = replace $path $lang ".md" }}
{{end}}
<script>
var oid = "views_{{ .Path }}"
var oid_likes = "likes_{{ .Path }}"
var oid = "views_{{ $path }}"
var oid_likes = "likes_{{ $path }}"
</script>
{{ end }}
{{ $jsPage := resources.Get "js/page.js" }}
{{ $jsPage = $jsPage | resources.Minify | resources.Fingerprint "sha512" }}
<script type="text/javascript" src="{{ $jsPage.RelPermalink }}" integrity="{{ $jsPage.Data.Integrity }}"></script>

View file

@ -86,12 +86,15 @@
{{ partial "related.html" . }}
</div>
{{ with .File }}
<script>
var oid = "views_{{ .Path }}"
var oid_likes = "likes_{{ .Path }}"
{{ $path := .File.Path }}
{{range .AllTranslations}}
{{ $lang := print "." .Lang ".md" }}
{{ $path = replace $path $lang ".md" }}
{{end}}
<script>
var oid = "views_{{ $path }}"
var oid_likes = "likes_{{ $path }}"
</script>
{{ end }}
{{ $jsPage := resources.Get "js/page.js" }}
{{ $jsPage = $jsPage | resources.Minify | resources.Fingerprint "sha512" }}
<script type="text/javascript" src="{{ $jsPage.RelPermalink }}" integrity="{{ $jsPage.Data.Integrity }}"></script>

View file

@ -4,7 +4,12 @@
{{ else if eq .Kind "term"}}
<span id="likes_term_{{ .Page.Data.Term }}"
{{ else }}
<span id="likes_{{ .File.Path }}"
{{ $path := .File.Path }}
{{range .AllTranslations}}
{{ $lang := print "." .Lang ".md" }}
{{ $path = replace $path $lang ".md" }}
{{end}}
<span id="likes_{{ $path }}"
{{ end }}
class="animate-pulse inline-block text-transparent max-h-3 rounded-full mt-[-2px] align-middle bg-neutral-300 dark:bg-neutral-400" title="likes">loading</span>
<span class="inline-block align-text-bottom">{{ partial "icon.html" "heart" }}</span>

View file

@ -4,7 +4,12 @@
{{ else if eq .Kind "term"}}
<span id="views_term_{{ .Page.Data.Term }}"
{{ else }}
<span id="views_{{ .File.Path }}"
{{ $path := .File.Path }}
{{range .AllTranslations}}
{{ $lang := print "." .Lang ".md" }}
{{ $path = replace $path $lang ".md" }}
{{end}}
<span id="views_{{ $path }}"
{{ end }}
class="animate-pulse inline-block text-transparent max-h-3 rounded-full mt-[-2px] align-middle bg-neutral-300 dark:bg-neutral-400" title="views">loading</span>
<span class="inline-block align-text-bottom">{{ partial "icon.html" "eye" }}</span>