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 liked_page = false
var id = oid ? oid.replaceAll("/", "-") : oid
var id_likes = oid_likes ? oid_likes.replaceAll("/", "-") : oid_likes
if (typeof auth !== 'undefined') { if (typeof auth !== 'undefined') {
var id = oid ? oid.replaceAll("/", "-") : oid
var viewed = localStorage.getItem(id); var viewed = localStorage.getItem(id);
if (!viewed) { 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); var liked = localStorage.getItem(id_likes);
if (liked) { if (liked) {
@ -97,7 +98,6 @@ function remove_like_article(id_likes) {
} }
function process_article() { function process_article() {
var id_likes = oid_likes ? oid_likes.replaceAll("/", "-") : oid_likes
if (!liked_page) { if (!liked_page) {
like_article(id_likes) like_article(id_likes)
} else { } 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"> <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") }} {{ partial "article-meta/list.html" (dict "context" . "scope" "single") }}
</div> </div>
{{ with .File }}
{{ $path := .File.Path }}
{{range .AllTranslations}}
{{ $lang := print "." .Lang ".md" }}
{{ $path = replace $path $lang ".md" }}
{{end}}
<script> <script>
var oid = "views_{{ .Path }}" var oid = "views_{{ $path }}"
var oid_likes = "likes_{{ .Path }}" var oid_likes = "likes_{{ $path }}"
</script> </script>
{{ end }}
{{ $jsPage := resources.Get "js/page.js" }} {{ $jsPage := resources.Get "js/page.js" }}
{{ $jsPage = $jsPage | resources.Minify | resources.Fingerprint "sha512" }} {{ $jsPage = $jsPage | resources.Minify | resources.Fingerprint "sha512" }}
<script type="text/javascript" src="{{ $jsPage.RelPermalink }}" integrity="{{ $jsPage.Data.Integrity }}"></script> <script type="text/javascript" src="{{ $jsPage.RelPermalink }}" integrity="{{ $jsPage.Data.Integrity }}"></script>

View file

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

View file

@ -4,7 +4,12 @@
{{ else if eq .Kind "term"}} {{ else if eq .Kind "term"}}
<span id="likes_term_{{ .Page.Data.Term }}" <span id="likes_term_{{ .Page.Data.Term }}"
{{ else }} {{ 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 }} {{ 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> 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> <span class="inline-block align-text-bottom">{{ partial "icon.html" "heart" }}</span>

View file

@ -4,7 +4,12 @@
{{ else if eq .Kind "term"}} {{ else if eq .Kind "term"}}
<span id="views_term_{{ .Page.Data.Term }}" <span id="views_term_{{ .Page.Data.Term }}"
{{ else }} {{ 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 }} {{ 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> 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> <span class="inline-block align-text-bottom">{{ partial "icon.html" "eye" }}</span>