From 8b132ffa0e2d6b8f797f50ce245a90e0a92787f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20Cora=C3=A7=C3=A3o?= Date: Mon, 12 Dec 2022 23:04:27 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8Term=20add=20likes=20and=20views?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/_default/params.toml | 1 + layouts/_default/term.html | 10 +++++++ layouts/partials/article-meta-term.html | 36 +++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 layouts/partials/article-meta-term.html diff --git a/config/_default/params.toml b/config/_default/params.toml index 12cefaf7..aec40a4a 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -96,6 +96,7 @@ enableCodeCopy = true [term] #showHero = true #heroStyle = "background" # valid options: basic, big, background, thumbAndBackground + #showSummary = false #showViews = false #showLikes = false #showTableOfContents = true diff --git a/layouts/_default/term.html b/layouts/_default/term.html index cc1e849b..d84ef675 100644 --- a/layouts/_default/term.html +++ b/layouts/_default/term.html @@ -4,12 +4,22 @@ {{ partial "breadcrumbs.html" . }} {{ end }}

{{ .Title }}

+
+ {{ partial "article-meta-term.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-term.html b/layouts/partials/article-meta-term.html new file mode 100644 index 00000000..63acb4e3 --- /dev/null +++ b/layouts/partials/article-meta-term.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.term.showViews | default false)) }} +{{ $meta.Add "partials" (slice (partial "meta/views.html" .)) }} +{{ end }} + +{{ if (.Params.showLikes | default (.Site.Params.term.showLikes | default false)) }} +{{ $meta.Add "partials" (slice (partial "meta/likes.html" .)) }} +{{ end }} + +{{ if and (eq $scope "single") (.Params.showLikes | default (.Site.Params.term.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