refactor templates layout

@see https://gohugo.io/templates/new-templatesystem-overview/
This commit is contained in:
Ben Goldsworthy 2025-06-06 15:36:06 +02:00
parent a83f339dc8
commit 230c46411b
No known key found for this signature in database
102 changed files with 2 additions and 2 deletions

View file

@ -0,0 +1,62 @@
<!--
Partial to render attribution for a resource.
@params sc Site context.
@params pc Page context.
@params attr Resource attribution.
@params attr_link Resource link. Optional.
@params attr_license Resource license. Optional.
@params attr_license_link Resource license link. Optional.
-->
<!-- Validation -->
{{- if ( not ( isset . "sc" ) ) -}}
{{- errorf "No site context received" -}}
{{- end -}}
{{- if ( not ( isset . "pc" ) ) -}}
{{- errorf "No page context received (%q)" .sc.Page.File.Dir -}}
{{- end -}}
{{- if ( not ( isset . "params" ) ) -}}
{{- errorf "No params given (%q)" .pc.File.Path -}}
{{- end -}}
{{- if ( not ( isset .params "attr" ) ) -}}
{{- errorf "No attr given (%q)" .pc.File.Path -}}
{{- end -}}
<!-- Variable assignment -->
{{- $attr := .params.attr -}}
{{- $attr_link := .params.attrlink -}}
{{- $attr_licence := .params.attrlicence -}}
{{- $attr_licence_link := .params.attrlicencelink -}}
<!-- Rendering -->
<p class="attr">
{{- with $attr_link -}}
<a href="{{ . }}" target="_blank" rel="noopener">
{{- end -}}
{{- $attr | safeHTML -}}
{{- if $attr_link -}}
</a>
{{- end -}}
{{- if $attr_licence }} (
{{- $attr_licence_link := partialCached "util/get_licence_link.html" ( dict "licences_data" .sc.Site.Data.licences "licence" $attr_licence "licence_link" $attr_licence_link ) $attr_licence $attr_licence_link -}}
{{- with $attr_licence_link -}}
<a href="{{- . -}}" target="_blank" rel="noopener">
{{- end -}}
{{- $attr_licence -}}
{{- with $attr_licence_link -}}
</a>
{{- end -}}
)
{{- end -}}
<p>

View file

@ -0,0 +1,12 @@
<!--
Render an audio track in an interactive player.
@params context The audio media file.
-->
{{- $src := . -}}
<audio class="u-audio figure__audio" itemprop="audio" controls>
<source src="{{ $src.RelPermalink }}" type="{{ $src.MediaType }}" />
<p>Your browser doesn't support embedded audio, <a href="{{ $src.RelPermalink }}">view the audio here</a>.</p>
</audio>

View file

@ -0,0 +1,53 @@
<!--
Render an image in a context-appropriate format and size.
@params src Image media file.
@params raw Force raw image only. Optional.
-->
<!-- Variable assignment -->
{{- $src := .src -}}
{{- $hint := default ( index $src.Params "hint" ) "" }}
{{- $format := cond ( and ( isset . "raw" ) .raw ) "" "webp" -}}
{{- $isResizable := not ( in ( slice "svg" "gif" ) $src.MediaType.SubType ) -}}
<!-- Rendering -->
<picture
class="picture"
itemprop="image"
>
{{ if $isResizable -}}
<source
srcset="{{- partialCached "images/get-image.html" ( dict "img" $src "size" "same" "format" $format ) $src.Title -}}"
/>
{{- if gt $src.Width 1200 -}}
<source
srcset="{{- partialCached "images/get-image.html" ( dict "img" $src "size" "1200x" "format" $format ) ( printf "%s-1200x" $src.Title ) -}}"
media="(max-width: 1200px)"
/>
{{- end -}}
{{- if gt $src.Width 800 -}}
<source
srcset="{{- partialCached "images/get-image.html" ( dict "img" $src "size" "800x" "format" $format ) ( printf "%s-800x" $src.Title ) -}}"
media="(max-width: 800px)"
/>
{{- end -}}
{{- end }}
<img
class="u-photo picture__image"
{{ if not $isResizable -}}
src="{{- $src.RelPermalink -}}"
{{- else -}}
src="{{- partialCached "images/get-image.html" ( dict "img" $src "format" $format ) $src.Title -}}"
width="{{- $src.Width -}}"
height="{{- $src.Height -}}"
{{- end }}
{{ with $src.Params.alt -}}alt="{{- . -}}"{{- end }}
{{ with $src.Params.title -}}title="{{- . -}}"{{- end }}
loading="lazy"
role="img"
/>
</picture>

View file

@ -0,0 +1,26 @@
<!--
Render a video in an interactive player.
@params context Video media file.
@params page_file_path Filepath of the calling file for error messages.
-->
{{- $src := .src -}}
<video
class="u-video figure__video"
controls
itemprop="video"
preload="none"
src="{{ $src.RelPermalink }}"
poster="
{{- if $src.Params.poster -}}
{{- $posterSrc := $.Page.Resources.GetMatch ( .Get $src.Params.poster ) -}}
{{- partialCached "images/get-image.html" ( dict "img" $posterSrc ) $posterSrc.Title -}}
{{- else -}}
{{- erroridf "a11y-video-poster" "No poster defined for resource %q (%q)" $src.RelPermalink .page_file_path -}}
{{- end -}}
"
>
Your browser doesn't support embedded video, <a href="{{ $src.RelPermalink }}">view the video here</a>.
</video>