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 }}
</span>
{{ end }}
{{ partial "cover.html" . }}
{{ partial "cover.html" (dict "ctx" . "isCoverCaptionEnabled" true) }}
{{ if (.Params.Toc | default .Site.Params.Toc) }}
<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 -}}
{{- $autoCover := default $.Site.Params.autoCover false }}
{{- if index .Params "cover" -}}
{{- if .Resources.GetMatch .Params.Cover }}
{{- $cover = (.Resources.GetMatch .Params.Cover).RelPermalink -}}
{{- if index $ctx.Params "cover" -}}
{{- if .Resources.GetMatch $ctx.Params.Cover }}
{{- $cover = (.Resources.GetMatch $ctx.Params.Cover).RelPermalink -}}
{{- else -}}
{{- $cover = absURL .Params.Cover -}}
{{- $cover = absURL $ctx.Params.Cover -}}
{{- end -}}
{{- else if $.Site.Params.AutoCover -}}
{{- if (not .Params.Cover) -}}
{{- if (not $ctx.Params.Cover) -}}
{{- if .Resources.GetMatch "cover.*" -}}
{{- $cover = (.Resources.GetMatch "cover.*").RelPermalink -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{if $cover -}}
{{ if .Params.coverCaption }}
{{- if $cover -}}
{{ if and $ctx.Params.coverCaption $isCoverCaptionEnabled }}
<figure>
<!-- Cover image found -->
<img src="{{ $cover }}"
class="post-cover"
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>
{{ else }}
<!-- Cover image found -->
<img src="{{ $cover }}"
class="post-cover"
alt="{{ .Title | plainify | default " " }}"
title="{{ .Params.CoverCredit |plainify|default "Cover Image" }}" />
title="{{ $ctx.Params.CoverCredit |plainify|default "Cover Image" }}" />
{{ end }}
{{- end }}

View File

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