From b391a94c89cd43bbe6ff3cb8324a6ea8d48ad26f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20Cora=C3=A7=C3=A3o?= Date: Mon, 12 Dec 2022 21:58:14 +0000 Subject: [PATCH 01/11] :bookmark: updated theme version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5e4d2b71..fc25760a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hugo-blowfish-theme", - "version": "2.17.1", + "version": "2.18.0", "description": "Blowfish theme for Hugo", "scripts": { "fullinstall": "npm run preinstall && npm install && npm run postinstall", From 3da417f6c98203c54e744a3063d8c7d2b9fc6e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20Cora=C3=A7=C3=A3o?= Date: Mon, 12 Dec 2022 22:07:14 +0000 Subject: [PATCH 02/11] =?UTF-8?q?=F0=9F=8E=A8=20Add=20relevant=20parameter?= =?UTF-8?q?s=20to=20params.toml=20file=20for=20both=20taxonomy=20and=20ter?= =?UTF-8?q?m?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/_default/params.toml | 24 +++++++++++++++++++++++- exampleSite/config/_default/params.toml | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/config/_default/params.toml b/config/_default/params.toml index 6444d411..d623402d 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -82,7 +82,29 @@ enableCodeCopy = true excludedKinds = [] [taxonomy] - showTermCount = true + #showTermCount = true + #showHero = true + #heroStyle = "background" # valid options: basic, big, background, thumbAndBackground + #layoutBackgroundBlur = true # only used when heroStyle equals background + #layoutBackgroundHeaderSpace = false + #showViews = true + #showLikes = true + #showTableOfContents = true + #cardView = true + +[term] + #showHero = true + #heroStyle = "background" # valid options: basic, big, background, thumbAndBackground + #layoutBackgroundBlur = true # only used when heroStyle equals background + #layoutBackgroundHeaderSpace = false + #showSummary = false + #showViews = true + #showLikes = true + #showTableOfContents = true + #showCards = true + #groupByYear = false + #cardViewScreenWidth = false + #cardView = true [firebase] # apiKey = "XXXXXX" diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 55137936..5fdc6350 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -82,6 +82,29 @@ mainSections = ["docs"] [taxonomy] showTermCount = true + showHero = true + heroStyle = "background" # valid options: basic, big, background, thumbAndBackground + layoutBackgroundBlur = true # only used when heroStyle equals background + layoutBackgroundHeaderSpace = false + showViews = true + showLikes = true + showTableOfContents = true + cardView = true + +[term] + showHero = true + heroStyle = "background" # valid options: basic, big, background, thumbAndBackground + layoutBackgroundBlur = true # only used when heroStyle equals background + layoutBackgroundHeaderSpace = false + showSummary = false + showViews = true + showLikes = true + showTableOfContents = true + showCards = true + groupByYear = false + cardView = true + cardViewScreenWidth = false + [firebase] apiKey = "AIzaSyB5tqlqDky77Vb4Tc4apiHV4hRZI18KGiY" From 2e222bf5aa5055353e220d077911d91f2f556d1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20Cora=C3=A7=C3=A3o?= Date: Mon, 12 Dec 2022 22:11:21 +0000 Subject: [PATCH 03/11] =?UTF-8?q?=F0=9F=94=A7=20Add=20default=20values=20t?= =?UTF-8?q?o=20the=20above=20new=20sections=20in=20params.toml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/_default/params.toml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/config/_default/params.toml b/config/_default/params.toml index d623402d..c24a7cae 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -87,24 +87,23 @@ enableCodeCopy = true #heroStyle = "background" # valid options: basic, big, background, thumbAndBackground #layoutBackgroundBlur = true # only used when heroStyle equals background #layoutBackgroundHeaderSpace = false - #showViews = true - #showLikes = true + #showViews = false + #showLikes = false #showTableOfContents = true - #cardView = true + #cardView = false [term] #showHero = true #heroStyle = "background" # valid options: basic, big, background, thumbAndBackground #layoutBackgroundBlur = true # only used when heroStyle equals background #layoutBackgroundHeaderSpace = false - #showSummary = false - #showViews = true - #showLikes = true + #showViews = false + #showLikes = false #showTableOfContents = true - #showCards = true + #showCards = false #groupByYear = false #cardViewScreenWidth = false - #cardView = true + #cardView = false [firebase] # apiKey = "XXXXXX" From 3034722b471ba6f6a9c690d2f1570455c048a815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20Cora=C3=A7=C3=A3o?= Date: Mon, 12 Dec 2022 22:34:28 +0000 Subject: [PATCH 04/11] =?UTF-8?q?=E2=9C=A8Taxonomy=20add=20likes=20and=20v?= =?UTF-8?q?iews?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/page.js | 106 ++++++++++++++++++++ config/_default/params.toml | 3 +- exampleSite/config/_default/params.toml | 1 + layouts/_default/taxonomy.html | 12 ++- layouts/partials/article-meta-taxonomy.html | 36 +++++++ 5 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 assets/js/page.js create mode 100644 layouts/partials/article-meta-taxonomy.html diff --git a/assets/js/page.js b/assets/js/page.js new file mode 100644 index 00000000..714b5d20 --- /dev/null +++ b/assets/js/page.js @@ -0,0 +1,106 @@ +var liked_page = false + +if (typeof auth !== 'undefined') { + var id = oid ? oid.replaceAll("/", "-") : oid + var viewed = localStorage.getItem(id); + + if (!viewed) { + auth.signInAnonymously() + .then(() => { + var docRef = db.collection('views').doc(id) + localStorage.setItem(id, true); + docRef.get().then((doc) => { + if (doc.exists) { + db.collection('views').doc(id).update({ + views: firebase.firestore.FieldValue.increment(1) + }); + } else { + db.collection('views').doc(id).set({ views: 1 }) + } + }).catch((error) => { + console.log("Error getting document:", error); + }); + }) + .catch((error) => { + var errorCode = error.code; + var errorMessage = error.message; + console.error(errorCode, errorMessage) + }); + } + + var id_likes = oid_likes ? oid_likes.replaceAll("/", "-") : oid_likes + var liked = localStorage.getItem(id_likes); + + if (liked) { + liked_page = true + document.querySelectorAll("span[id='likes_button_heart']")[0].style.display = "" + document.querySelectorAll("span[id='likes_button_emtpty_heart']")[0].style.display = "none" + document.querySelectorAll("span[id='likes_button_text']")[0].innerText = "" + } + +} + +function like_article(id_likes) { + auth.signInAnonymously() + .then(() => { + var docRef = db.collection('likes').doc(id_likes) + docRef.get().then((doc) => { + liked_page = true + localStorage.setItem(id_likes, true); + document.querySelectorAll("span[id='likes_button_heart']")[0].style.display = "" + document.querySelectorAll("span[id='likes_button_emtpty_heart']")[0].style.display = "none" + document.querySelectorAll("span[id='likes_button_text']")[0].innerText = "" + if (doc.exists) { + db.collection('likes').doc(id_likes).update({ + likes: firebase.firestore.FieldValue.increment(1) + }); + } else { + db.collection('likes').doc(id_likes).set({ likes: 1 }) + } + }).catch((error) => { + console.log("Error getting document:", error); + }); + }) + .catch((error) => { + var errorCode = error.code; + var errorMessage = error.message; + console.error(errorCode, errorMessage) + }); +} + +function remove_like_article(id_likes) { + auth.signInAnonymously() + .then(() => { + var docRef = db.collection('likes').doc(id_likes) + docRef.get().then((doc) => { + liked_page = false + localStorage.removeItem(id_likes); + document.querySelectorAll("span[id='likes_button_heart']")[0].style.display = "none" + document.querySelectorAll("span[id='likes_button_emtpty_heart']")[0].style.display = "" + document.querySelectorAll("span[id='likes_button_text']")[0].innerText = "\xa0Like" + if (doc.exists) { + db.collection('likes').doc(id_likes).update({ + likes: firebase.firestore.FieldValue.increment(-1) + }); + } else { + db.collection('likes').doc(id_likes).set({ likes: 0 }) + } + }).catch((error) => { + console.log("Error getting document:", error); + }); + }) + .catch((error) => { + var errorCode = error.code; + var errorMessage = error.message; + console.error(errorCode, errorMessage) + }); +} + +function process_article() { + var id_likes = oid_likes ? oid_likes.replaceAll("/", "-") : oid_likes + if (!liked_page) { + like_article(id_likes) + } else { + remove_like_article(id_likes) + } +} \ No newline at end of file diff --git a/config/_default/params.toml b/config/_default/params.toml index c24a7cae..dd43b62c 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -82,11 +82,12 @@ enableCodeCopy = true excludedKinds = [] [taxonomy] - #showTermCount = true + showTermCount = true #showHero = true #heroStyle = "background" # valid options: basic, big, background, thumbAndBackground #layoutBackgroundBlur = true # only used when heroStyle equals background #layoutBackgroundHeaderSpace = false + showBreadcrumbs = false #showViews = false #showLikes = false #showTableOfContents = true diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 5fdc6350..bd63ad47 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -86,6 +86,7 @@ mainSections = ["docs"] heroStyle = "background" # valid options: basic, big, background, thumbAndBackground layoutBackgroundBlur = true # only used when heroStyle equals background layoutBackgroundHeaderSpace = false + showBreadcrumbs = false showViews = true showLikes = true showTableOfContents = true diff --git a/layouts/_default/taxonomy.html b/layouts/_default/taxonomy.html index 75bd293f..8c523d1d 100644 --- a/layouts/_default/taxonomy.html +++ b/layouts/_default/taxonomy.html @@ -1,15 +1,25 @@ {{ define "main" }}
- {{ if .Params.showBreadcrumbs | default (.Site.Params.list.showBreadcrumbs | default false) }} + {{ if .Params.showBreadcrumbs | default (.Site.Params.taxonomy.showBreadcrumbs | default false) }} {{ partial "breadcrumbs.html" . }} {{ end }}

{{ .Title }}

+
+ {{ partial "article-meta-taxonomy.html" (dict "context" . "scope" "single") }} +
{{ if .Content }}
{{ .Content | emojify }}
+ + {{ $jsPage := resources.Get "js/page.js" }} + {{ $jsPage = $jsPage | resources.Minify | resources.Fingerprint "sha512" }} +
{{ end }}
diff --git a/layouts/partials/article-meta-taxonomy.html b/layouts/partials/article-meta-taxonomy.html new file mode 100644 index 00000000..d8d0142e --- /dev/null +++ b/layouts/partials/article-meta-taxonomy.html @@ -0,0 +1,36 @@ +{{/* Determine the correct context and scope */}} +{{/* This allows for different logic depending on where the partial is called */}} +{{ $context := . }} +{{ $scope := default nil }} + +{{ if (reflect.IsMap . ) }} +{{ $context = .context }} +{{ $scope = cond (not .scope) nil .scope }} +{{ end }} + +{{ with $context }} +{{ $meta := newScratch }} + +{{/* Gather partials for this context */}} + +{{ if (.Params.showViews | default (.Site.Params.taxonomy.showViews | default false)) }} +{{ $meta.Add "partials" (slice (partial "meta/views.html" .)) }} +{{ end }} + +{{ if (.Params.showLikes | default (.Site.Params.taxonomy.showLikes | default false)) }} +{{ $meta.Add "partials" (slice (partial "meta/likes.html" .)) }} +{{ end }} + +{{ if and (eq $scope "single") (.Params.showLikes | default (.Site.Params.taxonomy.showLikes | default false)) }} +{{ $meta.Add "partials" (slice (partial "meta/likes_button.html" .)) }} +{{ end }} + + +
+ {{/* Output partials */}} + {{ with ($meta.Get "partials") }} + {{ delimit . "·" }} + {{ end }} +
+ +{{ end }} \ No newline at end of file From 8171739c7efff3865b91ce650165c082cef9861f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20Cora=C3=A7=C3=A3o?= Date: Mon, 12 Dec 2022 22:43:05 +0000 Subject: [PATCH 05/11] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor=20articles?= =?UTF-8?q?=20and=20list=20to=20use=20page.js=20logic=20instead=20of=20inl?= =?UTF-8?q?ine=20js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layouts/_default/list.html | 118 ++--------------------------------- layouts/_default/single.html | 118 ++--------------------------------- 2 files changed, 10 insertions(+), 226 deletions(-) diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 0919d81c..54748237 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -36,120 +36,12 @@ {{ .Content | emojify }} + {{ $jsPage := resources.Get "js/page.js" }} + {{ $jsPage = $jsPage | resources.Minify | resources.Fingerprint "sha512" }} +
{{ if gt .Pages 0 }} diff --git a/layouts/_default/single.html b/layouts/_default/single.html index c5a1a0d6..908a0c92 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -38,120 +38,12 @@ {{ partial "series-closed.html" . }} + {{ $jsPage := resources.Get "js/page.js" }} + {{ $jsPage = $jsPage | resources.Minify | resources.Fingerprint "sha512" }} +