Merge pull request #319 from nunocoracao/310-term-add-likes-and-views

Term add likes and views
This commit is contained in:
Nuno Coração 2022-12-12 23:05:10 +00:00 committed by GitHub
commit c40b75a601
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 0 deletions

View file

@ -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

View file

@ -4,12 +4,22 @@
{{ partial "breadcrumbs.html" . }}
{{ end }}
<h1 class="mt-0 text-4xl font-extrabold text-neutral-900 dark:text-neutral">{{ .Title }}</h1>
<div class="mt-1 mb-2 text-base text-neutral-500 dark:text-neutral-400 print:hidden">
{{ partial "article-meta-term.html" (dict "context" . "scope" "single") }}
</div>
</header>
{{ if .Content }}
<section class="flex flex-col max-w-full mt-0 prose dark:prose-invert lg:flex-row">
<div class="min-w-0 min-h-0 max-w-prose">
{{ .Content | emojify }}
</div>
<script>
var oid = "views_{{ .File.Path }}"
var oid_likes = "likes_{{ .File.Path }}"
</script>
{{ $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>
</section>
{{ end }}
<section class="mt-5 space-y-10 w-full">

View file

@ -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 }}
<div class="flex flex-row flex-wrap items-center">
{{/* Output partials */}}
{{ with ($meta.Get "partials") }}
{{ delimit . "<span class=\"px-2 text-primary-500\">&middot;</span>" }}
{{ end }}
</div>
{{ end }}