chore: show figure only on post pages

This commit is contained in:
Mirus 2024-08-23 14:35:27 +03:00
parent 9795a7535f
commit 4779fd62c0
3 changed files with 29 additions and 12 deletions

View File

@ -29,7 +29,7 @@
{{ end }} {{ end }}
</span> </span>
{{ end }} {{ end }}
{{ partial "cover.html" . }} {{ partial "cover.html" (dict "ctx" . "isCoverCaptionEnabled" true) }}
{{ if (.Params.Toc | default .Site.Params.Toc) }} {{ if (.Params.Toc | default .Site.Params.Toc) }}
<div class="table-of-contents"> <div class="table-of-contents">

View File

@ -1,37 +1,54 @@
{{- $ctx := "" -}}
{{- $isCoverCaptionEnabled := default nil -}}
{{- if (reflect.IsMap . ) -}}
{{- /* Assign Custom Context */ -}}
{{- $ctx = .ctx -}}
{{- /* Assign value of .isCoverCaptionEnabled */ -}}
{{- $isCoverCaptionEnabled = cond (not .isCoverCaptionEnabled) nil .isCoverCaptionEnabled -}}
{{- else -}}
{{- /* Passing dot context, default behaviour */ -}}
{{- $ctx = . -}}
{{- /* Default isCoverCaptionEnabled for Dot Context */ -}}
{{- $isCoverCaptionEnabled = false -}}
{{- end -}}
{{- $cover := false -}} {{- $cover := false -}}
{{- $autoCover := default $.Site.Params.autoCover false }} {{- $autoCover := default $.Site.Params.autoCover false }}
{{- if index .Params "cover" -}} {{- if index $ctx.Params "cover" -}}
{{- if .Resources.GetMatch .Params.Cover }} {{- if .Resources.GetMatch $ctx.Params.Cover }}
{{- $cover = (.Resources.GetMatch .Params.Cover).RelPermalink -}} {{- $cover = (.Resources.GetMatch $ctx.Params.Cover).RelPermalink -}}
{{- else -}} {{- else -}}
{{- $cover = absURL .Params.Cover -}} {{- $cover = absURL $ctx.Params.Cover -}}
{{- end -}} {{- end -}}
{{- else if $.Site.Params.AutoCover -}} {{- else if $.Site.Params.AutoCover -}}
{{- if (not .Params.Cover) -}} {{- if (not $ctx.Params.Cover) -}}
{{- if .Resources.GetMatch "cover.*" -}} {{- if .Resources.GetMatch "cover.*" -}}
{{- $cover = (.Resources.GetMatch "cover.*").RelPermalink -}} {{- $cover = (.Resources.GetMatch "cover.*").RelPermalink -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{if $cover -}} {{- if $cover -}}
{{ if .Params.coverCaption }} {{ if and $ctx.Params.coverCaption $isCoverCaptionEnabled }}
<figure> <figure>
<!-- Cover image found --> <!-- Cover image found -->
<img src="{{ $cover }}" <img src="{{ $cover }}"
class="post-cover" class="post-cover"
alt="{{ .Title | plainify | default " " }}" alt="{{ .Title | plainify | default " " }}"
title="{{ .Params.CoverCredit |plainify|default "Cover Image" }}" /> title="{{ $ctx.Params.CoverCredit |plainify|default "Cover Image" }}" />
<figcaption class="right">{{ .Params.coverCaption | safeHTML }}</figcaption> <figcaption class="right">{{ $ctx.Params.coverCaption | safeHTML }}</figcaption>
</figure> </figure>
{{ else }} {{ else }}
<!-- Cover image found --> <!-- Cover image found -->
<img src="{{ $cover }}" <img src="{{ $cover }}"
class="post-cover" class="post-cover"
alt="{{ .Title | plainify | default " " }}" alt="{{ .Title | plainify | default " " }}"
title="{{ .Params.CoverCredit |plainify|default "Cover Image" }}" /> title="{{ $ctx.Params.CoverCredit |plainify|default "Cover Image" }}" />
{{ end }} {{ end }}
{{- end }} {{- end }}

View File

@ -67,7 +67,7 @@ HERE INSERT ANY CUSTOM <script/> or <style/>
{{ end }} {{ end }}
</span> </span>
{{ end }} {{ end }}
{{ partial "cover.html" . }} {{ partial "cover.html" (dict "ctx" . "isCoverCaptionEnabled" true) }}
{{ if (.Params.Toc | default .Site.Params.Toc) }} {{ if (.Params.Toc | default .Site.Params.Toc) }}
<div class="table-of-contents"> <div class="table-of-contents">