Omphaloskepsis-2/layouts/shortcodes/figure.html

97 lines
4.4 KiB
HTML
Raw Normal View History

2023-02-18 00:38:04 +00:00
{{- if ( and ( .Get "src" ) ( .Get "chart-id" ) ) -}}
{{- errorf "Both chart ID and resource source defined" -}}
{{- end -}}
2023-01-29 18:50:16 +00:00
{{ $src := $.Page.Resources.GetMatch (.Get "src") }}
2023-02-18 00:38:04 +00:00
{{ $linkedResource := $.Page.Resources.GetMatch (.Get "link") }}
2022-11-11 05:48:02 +00:00
2023-02-18 00:38:04 +00:00
<figure class="article__figure{{ with .Get "class" }} {{ . }}{{ end }}">
{{- with .Get "chart-id" -}}
<canvas class="figure__chart" id="{{ . }}">
You must enable Javascript to view this chart.
</canvas>
{{- else -}}
{{- if .Get "link" -}}
{{- if $linkedResource }}
<a href="{{ $linkedResource.RelPermalink }}"{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>
{{ else }}
<a
href="{{ .Get "link" }}"
{{- with .Get "target" -}}
target="{{ . }}"
{{- else -}}
{{ warnf "No target defined for non-page resource link %q" ( .Get "link" ) -}}
{{- end -}}
{{- with .Get "rel" -}}
rel="{{ . }}"
{{- else -}}
{{- warnf "No rel defined for non-page resource link %q" ( .Get "link" ) -}}
{{- end -}}
>
{{ end }}
2023-01-29 18:50:16 +00:00
{{- end -}}
2023-02-18 00:38:04 +00:00
{{- if eq $src.ResourceType "image" -}}
<picture class="figure__picture">
<img class="figure__image"
{{ with $src.Resize "1500x webp" }}
src="{{ .RelPermalink }}"
{{ end }}
{{- if or ($src.Params.alt) (.Get "caption") }}
alt="{{ with $src.Params.alt }}{{ . }}{{ else }}{{ .Get "caption" | markdownify | plainify }}{{ end }}"
{{- end -}}
{{- with $src.Params.title }} title="{{ . }}"{{ end -}}
width="{{ $src.Width }}"
height="{{ $src.Height }}"
/>
</picture>
{{- else if eq $src.ResourceType "video" -}}
{{- if eq $src.MediaType "video/ogg" -}}
<audio class="figure__audio" controls>
<source src="{{ $src.RelPermalink }}" type="{{ $src.MediaType }}" />
<p>Your browser doesn't support embedded audio, but you can view the audio <a href="{{ $src.RelPermalink }}">here</a>.</p>
</audio>
{{- else -}}
<video class="figure__video"
controls
src="{{ $src.RelPermalink }}"
poster="{{ if $src.Params.poster }}{{ .Get $src.Params.poster }}{{ else }}{{ warnf "No poster defined for resource %q" $src.RelPermalink }}{{ end }}"
>
Your browser doesn't support embedded video, but you can view the video <a href="{{ $src.RelPermalink }}">here</a>.
</video>
{{- end -}}
{{- else if or ( ne $src.ResourceType "image" ) ( ne $src.ResourceType "video" ) -}}
{{- errorf "No handling for resource of type %q" $src.ResourceType -}}
{{- end -}}
{{- if .Get "link" }}</a>{{ end -}}
2023-01-29 18:50:16 +00:00
{{- end -}}
2023-02-18 00:38:04 +00:00
{{- if or ( .Get "caption" ) ( .Get "title" ) ( $src.Params.attr ) -}}
<figcaption class="figure__caption{{ if not ( or ( .Get "caption" ) ( .Get "title" ) ) }} figure__caption--no-height{{ end }}">
{{- with $src -}}
{{ if .Params.attrlink -}}
<a class="figcaption__attrlink" href="{{ .Params.attrlink }}"
{{- with .Params.attrtarget }} target="{{ . }}"{{ end -}}
{{- with .Params.attrrel }} rel="{{ . }}"{{ end -}}
>
{{- end -}}
{{- if .Params.attr -}}<p class="figcaption__attr">{{ .Params.attr | safeHTML }}{{ with .Params.attrlicence }} <span class="figcaption__licence">{{ . | safeHTML }}</span>{{ end }}</p>{{- end -}}
{{- if .Params.attrlink -}}
</a>
{{- end -}}
{{- with .Params.title -}}<h4 class="figcaption__title">{{ . }}</h4>{{- end -}}
2022-11-11 05:48:02 +00:00
{{- end -}}
2023-02-18 00:38:04 +00:00
{{- with .Get "title" -}}<h4 class="figcaption__title">{{ . }}</h4>{{- end -}}
{{- with .Get "caption" -}}
<p class="figcaption__caption">{{ . | markdownify }}
{{- with $src -}}
{{- if ( and ( eq .ResourceType "image" ) (or (gt .Width 2000) (gt .Height 2000) ) ) -}}
<span class="figcaption__full-size-link"><a href="{{ .RelPermalink }}">View full size</a></span>
{{- end -}}
{{- end -}}
</p>
2022-11-11 05:48:02 +00:00
{{- end -}}
</figcaption>
{{- end -}}
</figure>