Improve figures

- Add option to disable border and caption
This commit is contained in:
BBaoVanC 2021-10-27 09:48:13 -05:00
parent 0cfecdab18
commit 7ffa6c068c
Signed by: bbaovanc
GPG Key ID: 18089E4E3CCF1D3A
5 changed files with 29 additions and 4 deletions

View File

@ -112,7 +112,7 @@ img, video {
max-width: 100%; max-width: 100%;
} }
img:not(.noborder), video:not(.noborder) { figure.border img, figure.border video {
padding: 5px; padding: 5px;
border: 7px solid #1b5b9b; border: 7px solid #1b5b9b;
} }

View File

@ -19,7 +19,7 @@
{{ with .Resources.GetMatch "feature" }} {{ with .Resources.GetMatch "feature" }}
<div class="post-media"> <div class="post-media">
{{ partial "figure.html" . }} {{ partial "figure.html" (dict "src" . "border" true) }}
</div> </div>
{{ end }} {{ end }}

View File

@ -13,7 +13,7 @@
{{ with .Resources.GetMatch "feature" }} {{ with .Resources.GetMatch "feature" }}
<div class="post-media"> <div class="post-media">
{{ partial "figure.html" . }} {{ partial "figure.html" (dict "src" . "border" true) }}
</div> </div>
{{ end }} {{ end }}

View File

@ -1,4 +1,12 @@
{{ $hidecaption := index . "hidecaption" }}
{{ if index . "border" }}
<figure class="border">
{{ else }}
<figure> <figure>
{{ end }}
{{ with index . "src" }}
{{ $media := . | resources.Fingerprint "sha512" }} {{ $media := . | resources.Fingerprint "sha512" }}
{{ if eq .MediaType.MainType "image" }} {{ if eq .MediaType.MainType "image" }}
<img src="{{ $media.Permalink }}" alt="{{ $media.Title }}" /> <img src="{{ $media.Permalink }}" alt="{{ $media.Title }}" />
@ -9,9 +17,13 @@
</video> </video>
{{ end }} {{ end }}
{{ if not $hidecaption }}
{{ with $media.Title }} {{ with $media.Title }}
<figcaption> <figcaption>
{{ . | markdownify }} {{ . | markdownify }}
</figcaption> </figcaption>
{{ end }} {{ end }}
{{ end }}
{{ end }}
</figure> </figure>

View File

@ -1,2 +1,15 @@
{{ $resource := $.Page.Resources.GetMatch (.Get "src") }} {{ $resource := $.Page.Resources.GetMatch (.Get "src") }}
{{ partial "figure.html" $resource }}
{{ $border := false }}
{{ if .Get "border" }}
{{ $border = true }}
{{ end }}
{{ $hidecaption := false }}
{{ if .Get "hidecaption" }}
{{ $hidecaption = true }}
{{ end }}
<p>
{{ partial "figure.html" (dict "src" $resource "border" $border "hidecaption" $hidecaption) }}
</p>