This commit is contained in:
Ben Goldsworthy 2024-04-02 20:36:21 +01:00
parent 187900fd5b
commit 1fd9adcb52
Signed by: Rumperuu
SSH key fingerprint: SHA256:v3uompaUiPqV2w1/AIRWBSQOxr2dntH9Xs/y8fDnUPU
23 changed files with 1800 additions and 98 deletions

File diff suppressed because it is too large Load diff

View file

@ -30,14 +30,16 @@
}).addTo(map);
var latLons = [];
{{ range . }}
{{ with ( index $.Site.Data.locations . ) }}
L.marker([{{ .lat }}, {{ .lon }}]).addTo(map);
latLons.push([{{ .lat }}, {{ .lon }}]);
{{ else }}
{{ erroridf "missing-lat-lon" "Could not find lat-lon for %q (%q)" . $.File.Path }}
{{ end }}
{{ end }}
{{ $locations := partialCached "util/get_location_leaf_nodes.html.tmpl" $.Site.Data.locations -}}
{{- range . -}}
{{- with ( index $locations ( replaceRE `, [A-Z]+` "" . ) ) -}}
L.marker([{{ .lat }}, {{ .lon }}]).addTo(map);
latLons.push([{{ .lat }}, {{ .lon }}]);
{{- else -}}
{{- erroridf "missing-lat-lon" "Could not find lat-lon for %q (%q)" . $.File.Path -}}
{{- end -}}
{{- end }}
map.fitBounds(latLons);
</script>
{{ end }}
@ -75,10 +77,19 @@
</div>
{{ with .Resources.GetMatch .Params.featured_image }}
<p class="attr">
{{ if .Params.attrlink }}<a href="{{ .Params.attrlink }}" target="_blank" rel="noopener">{{ end }}
{{- .Params.Attr | safeHTML -}}
{{ if .Params.attrlink }}</a>{{ end }}
{{ if .Params.attrlicence }} ({{ .Params.attrlicence }}){{ end }}
{{- if .Params.attrlink -}}<a href="{{ .Params.attrlink }}" target="_blank" rel="noopener">{{- end -}}
{{- .Params.attr | safeHTML -}}
{{- if .Params.attrlink -}}</a>{{- end -}}
{{- if .Params.attrlicence }} (
{{- with .Params.attrlicencelink -}}
<a href="{{ . }}" target="_blank" rel="noopener">
{{- end -}}
{{- .Params.attrlicence -}}
{{- with .Params.attrlicencelink -}}
</a>
{{- end -}}
)
{{- end -}}
<p>
{{ end }}
</div>

View file

@ -30,15 +30,16 @@
}).addTo(map);
var latLons = [];
{{ range . }}
{{ with ( index $.Site.Data.locations . ) }}
L.marker([{{ .lat }}, {{ .lon }}]).addTo(map);
latLons.push([{{ .lat }}, {{ .lon }}]);
{{ else }}
{{ erroridf "missing-lat-lon" "Could not find lat-lon for %q (%q)" . $.File.Path }}
{{ end }}
{{ end }}
{{ $locations := partialCached "util/get_location_leaf_nodes.html.tmpl" $.Site.Data.locations -}}
{{- range . -}}
{{- with ( index $locations ( replaceRE `, [A-Z]+` "" . ) ) -}}
L.marker([{{ .lat }}, {{ .lon }}]).addTo(map);
latLons.push([{{ .lat }}, {{ .lon }}]);
{{- else -}}
{{- erroridf "missing-lat-lon" "Could not find lat-lon for %q (%q)" . $.File.Path -}}
{{- end -}}
{{- end }}
map.fitBounds(latLons);
if (map.getZoom() < 10) map.setZoom(10);
</script>
@ -112,10 +113,19 @@
</div>
{{ with .Resources.GetMatch .Params.featured_image }}
<p class="attr">
{{ if .Params.attrlink }}<a href="{{ .Params.attrlink }}" target="_blank" rel="noopener">{{ end }}
{{- .Params.Attr | safeHTML -}}
{{ if .Params.attrlink }}</a>{{ end }}
{{ if .Params.attrlicence }} ({{ .Params.attrlicence }}){{ end }}
{{- if .Params.attrlink -}}<a href="{{ .Params.attrlink }}" target="_blank" rel="noopener">{{- end -}}
{{- .Params.attr | safeHTML -}}
{{- if .Params.attrlink -}}</a>{{- end -}}
{{- if .Params.attrlicence }} (
{{- with .Params.attrlicencelink -}}
<a href="{{ . }}" target="_blank" rel="noopener">
{{- end -}}
{{- .Params.attrlicence -}}
{{- with .Params.attrlicencelink -}}
</a>
{{- end -}}
)
{{- end -}}
<p>
{{ end }}
</div>

View file

@ -152,7 +152,7 @@
{{ end }}
</ul>
</nav>
{{- partialCached "cv/timeline-legend.html" . -}}
{{- partialCached "cv/timeline-legend.html.tmpl" . -}}
{{- else -}}
<nav class="page-header__minor-links">
{{- partial "years-list.html" . -}}
@ -182,7 +182,7 @@
{{ else if eq .Type "cv" }}
<article class="site-content__body site-content__body--chart">
<div id="timeline" aria-label="Roles timeline" role="img">Javascript must be enabled to view this chart.</div>
<div id="timeline" aria-label="Roles timeline" role="img" height="70vh">Javascript must be enabled to view this chart.</div>
</article>
{{ else }}
{{ partial "items-grid.html" . }}

View file

@ -0,0 +1,63 @@
{{ define "title" }}
Locations | {{ .Site.Title }}
{{ end }}
{{ define "main-class" }}--section location-map{{ end }}
{{ define "header-scripts" }}
<link rel="stylesheet" href="/css/leaflet.css"/>
{{ end }}
{{ define "footer-scripts" }}
<script src="/js/leaflet.js"></script>
<script src="/js/leaflet-heat.js"></script>
<script>
var map = L.map('map').setView([55, -3], 3);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
{{- range $.Site.Data.locations -}}
/* L.marker([{{ .lat }}, {{ .lon }}]).addTo(map); */
{{- end -}}
{{- $locations := partialCached "util/get_location_leaf_nodes.html.tmpl" $.Site.Data.locations -}}
L.heatLayer(
[
{{- range .Site.AllPages -}}
{{- with .Params.locations -}}
{{- range . -}}
{{- with ( index $locations ( replaceRE `, [A-Z]+` "" . ) ) -}}
[ {{ .lat }}, {{ .lon }} ],
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
],
{
minOpacity: 0.5,
gradient: {0.2: 'blue', 0.5: 'lime', 1: 'red'}
}
).addTo(map);
</script>
{{ end }}
{{ define "main-header" }}
<header class="site-content__header">
<h1 class="page-title">{{ .Title | safeHTML }}.</h1>
{{ .Content }}
</header>
{{ end }}
{{ define "main-body" }}
<article class="site-content__body site-content__body--chart">
<div id="map" style="width: 100%; height: 500px; margin: 0; display: block;"></div>
<section style="grid-area: section-content">
{{- partial "util/render_recursive_list.html.tmpl" ( dict "sc" $ "pc" . "items" $.Site.Data.locations "schemaType" "Place" ) -}}
</section>
</article>
{{ end }}

View file

@ -0,0 +1,78 @@
<!--
Renders a work citation with semantic markup, called using the `cite` shortcode.
@params cite URI for work. Optional.
@params citeStyle Force a citation style. Optional.
@params href URI for citation, or 'asCite' to use value of `cite`. Optional.
@params schemaType The Schema.org `itemtype` value. Default 'CreativeWork'.
@params shortTitle Abbreviated display title. Optional.
@params title Title of the work to display.
@params titleLang Language code of a foreign-language work's title. Optional.
@params titleTr English translation of a foreign-language work's title. Optional.
-->
<!-- Optional parameter overrides (for nested citations) -->
{{- $cite := default .Params.cite ( .Scratch.Get "cite" ) -}}
{{- $title := default .Params.title ( .Scratch.Get "title" ) -}}
{{- $titleLang := default .Params.titleLang ( .Scratch.Get "titleLang" ) -}}
{{- $titleTr := default .Params.titleTr ( .Scratch.Get "titleTr" ) -}}
{{- $schemaType := default .Params.schemaType ( .Scratch.Get "schemaType" ) -}}
<!-- Validation -->
<!-- TODO: check `.Params.cite` is URI -->
{{- if ( and ( isset .Params "citeStyle" ) ( not ( in ( slice "inherit" "enquote" "normal" ) .Params.citeStyle ) ) ) -}}
{{- erroridf "invalid-citeStyle" "Invalid `citeStyle` value %q for %q" .Params.citeStyle $title -}}
{{- end -}}
<!-- TODO: check `.Params.href` is URI or 'asCite' -->
{{- if ( and $schemaType ( not ( in $.Site.Data.itemtypes $schemaType ) ) ) -}}
{{- erroridf "invalid-schemaType" "Invalid Schema.org type value %q for %q" $schemaType $title -}}
{{- end -}}
{{- if ( or $titleLang $titleTr ) -}}
{{- if ( not ( and $titleLang $titleTr ) ) -}}
{{- erroridf "invalid-foreign-title" "Must have both title translation and language set for foreign language title %q" $title -}}
{{- end -}}
{{- end -}}
<!-- Rendering -->
{{- $itemType := default "CreativeWork" $schemaType -}}
{{- if ( or ( in $.Site.Data.itemtypes $itemType ) ( eq .Params.suppress "true" ) ) -}}
{{- with .Params.href -}}
<a href="{{ if eq . "asCite" }}{{ $cite }}{{ else }}{{ . }}{{ end }}">
{{- end -}}
<cite
class="cite{{ with .Params.citeStyle }} cite--{{ . }}{{ end }}"
itemscope
itemprop="citation"
itemtype="https://schema.org/{{- $itemType -}}"
{{- if $titleLang -}}
lang="{{- $titleLang -}}"
title="{{- $titleTr -}}"
{{- end -}}>
{{- with $cite -}}
<meta itemprop="url" content="{{ . }}">
{{- end -}}
<span itemprop="name">
{{- if $titleLang -}}
<i lang="{{ $titleLang }}" title="{{ $titleTr }}">
{{- end -}}
{{- ( default $title .Params.shortTitle ) | markdownify | safeHTML -}}
{{- if $titleLang -}}
</i>
{{- end -}}
</span>{{- /**/ -}}
</cite>
{{- with .Params.href -}}
</a>
{{- end -}}
{{- else -}}
{{- erroridf "invalid-schema-type" "Invalid Schema.org type value %q for %q" $itemType $title -}}
{{- end -}}

View file

@ -1,3 +1,7 @@
<!--
Renders the table list of organisations.
-->
<section class="site-content__body">
<table class="organisations-table">
<thead>

View file

@ -0,0 +1,16 @@
<aside class="timeline__legend">
<div>
<label for="legend__past">Past</label>
<div id="legend__past">
<button id="past-unpaid" class="legend__button"><p><span class="colour-square colour-square--unpaid-past"></span> Unpaid</p></button>
<button id="past-paid" class="legend__button"><p><span class="colour-square colour-square--paid-past"></span> Paid</p></button>
</div>
</div>
<div>
<label for="legend__current">Current</label>
<div id="legend__current">
<button id="current-unpaid" class="legend__button"><p><span class="colour-square colour-square--unpaid-current"></span> Unpaid</p></button>
<button id="current-paid" class="legend__button"><p><span class="colour-square colour-square--paid-current"></span> Paid</p></button>
</div>
</div>
</aside>

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,37 @@
<!--
Render an image in a context-appropriate format and size.
@params context Image media file.
-->
<!-- Variable assignment -->
{{- $src := . -}}
{{- $isResizable := not ( in ( slice "svg" "gif" ) $src.MediaType.SubType ) -}}
<!-- Rendering -->
<picture
class="picture"
itemprop="image"
>
{{- if $isResizable -}}
<source srcset="{{- ($src.Resize "1200x webp").RelPermalink -}}" />
<source srcset="{{- ($src.Resize "800x png").RelPermalink -}}" media="(max-width: 800px)"/>
{{- end -}}
<img
class="u-photo picture__image"
{{- if not $isResizable -}}
src="{{- $src.RelPermalink -}}"
{{- else -}}
src="{{- ($src.Resize "1200x webp").RelPermalink -}}"
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,27 @@
<!--
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 := . -}}
<video
class="u-video figure__video"
controls
itemprop="video"
src="{{ $src.RelPermalink }}"
poster="
{{- if $src.Params.poster -}}
{{- $posterSrc := $.Page.Resources.GetMatch ( .Get $src.Params.poster ) -}}
{{- with $posterSrc.Resize "1200x webp" -}}
{{- .RelPermalink -}}
{{- end -}}
{{- 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>

View file

@ -0,0 +1,11 @@
<!--
Given a top-level section title slug [blog|cv|portfolio], returns all
`Pages` within that top-level section.
@param sc The site content (`$`)
@param section_slug The slug of the section to use [blog|cv|portfolio]
@returns Pages|nil
-->
{{- where ( ( .sc.GetPage "cv" ).Sections ) "Title" .section_title -}}

View file

@ -0,0 +1,14 @@
{{- $locations := .Params.location }}
{{- $location := .Params.location }}
{{- range $k, $v := $locations -}}
{{- if ( isset $v "lat" ) -}}
{{- partialCached "util/get_location_by_index.html" ( dict "locations" $v "location" $location ) $location -}}
{{- else if ( eq $k $location ) -}}
{{- with $v -}}
{{- return . -}}
{{- else -}}
{{- warnf "Location %q has no co-ordinates set" $k -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,18 @@
<!--
Returns all locations from `data/locations.json`.
@params locations dict<dict>
@returns dict<dict>
-->
{{- $locations := ( dict ) -}}
{{- range $k, $v := . -}}
{{- if ( isset $v "lat" ) -}}
{{- $locations = merge $locations ( dict $k $v ) -}}
{{- else -}}
{{- $locations = merge $locations ( partial "util/get_location_leaf_nodes.html.tmpl" . ) -}}
{{- end -}}
{{- end -}}
{{- return $locations -}}

View file

@ -0,0 +1,7 @@
<!--
Returns a list of valid values for the `rel` HTML attribute.
@returns slice
-->
{{- return slice "alternate" "author" "external" "help" "license" "me" "next" "nofollow" "noopener" "noreferrer" "opener" "prev" "privacy-policy" "search" "tag" "terms-of-service" -}}

View file

@ -0,0 +1,56 @@
<!--
Recursively render an ordered or unordered list from a set of arbitrarily-
deeply-nested items.
@params sc Site context
@params pc Page context
@params items Set of items to render a list from.
@params schemaType Schema.org type to apply. Optional.
@params listType "unordered" or "ordered". Default "unordered".
-->
<!-- Validation -->
{{- if not .sc.Site.Data.itemtypes -}}
{{- errorf "Can't access site context in partial (%q)" .pc.File.Path -}}
{{- end -}}
{{- if not .items -}}
{{- warnf "No items passed to list partial (%q)" .pc.File.Path -}}
{{- end -}}
{{- if ( and .schemaType ( not ( in .sc.Site.Data.itemtypes .schemaType ) ) ) -}}
{{- erroridf "invalid-schemaType" "Invalid Schema.org type value %q (%q)" .schemaType .pc.File.Path -}}
{{- end -}}
{{- if ( and .listType ( not ( in ( slice "unordered" "ordered" ) .listType ) ) ) -}}
{{- erroridf "invalid-listType" "Invalid list type value %q (%q)" .listType .pc.File.Path -}}
{{- end -}}
<!-- Default Assignment -->
{{- $schemaType := default "" .schemaType -}}
{{- $listType := default "unordered" .listType -}}
<!-- Rendering -->
{{- if ( eq $listType "unordered" ) -}}
<ul>
{{- else -}}
<ol>
{{- end -}}
{{- range $k, $v := .items -}}
<li itemscope itemtype="https://schema.org/Place">
{{- $k -}}
{{- if ( not ( isset $v "lat" ) ) -}}
{{- partial "util/render_recursive_list.html.tmpl" ( dict "sc" $.sc "pc" $.pc "items" $v "schemaType" $schemaType "listType" $listType ) -}}
{{- end -}}
</li>
{{- end -}}
{{- if ( eq $listType "unordered" ) -}}
</ul>
{{- else -}}
</ol>
{{- end -}}

View file

@ -17,16 +17,14 @@
<abbr lang="la" title="ibīdem [in the same place]">Ibid.</abbr>
{{- else -}}
<span itemprop="spokenByCharacter">{{- .Params.source | safeHTML -}}</span>
{{- if .Params.title -}}, <span itemprop="isBasedOn">{{- partial "cite.html" . -}}
{{- if .Params.titleSeries }} (
{{- .Scratch.SetInMap "Params" "title" .Params.titleSeries -}}
{{- .Scratch.SetInMap "Params" "titleLang" .Params.titleSeriesLang -}}
{{- .Scratch.SetInMap "Params" "titleTr" .Params.titleSeriesTr -}}
{{- .Scratch.SetInMap "Params" "cite" .Params.citeSeries -}}
{{- .Scratch.SetInMap "Params" "schemaType" .Params.schemaTypeSeries -}}
{{- .Scratch.SetInMap "Params" "suppress" "true" -}}
{{- .Scratch.SetInMap "parentCite" "Params" ( .Scratch.Get "Params" ) -}}
{{- partial "cite.html" ( .Scratch.Get "parentCite" ) -}}
{{- if .Params.title -}}, <span itemprop="isBasedOn">{{- partial "cite.html.tmpl" . -}}
{{- if ( isset .Params "titleSeries" ) }} (
{{- .Scratch.Set "cite" .Params.citeSeries -}}
{{- .Scratch.Set "title" .Params.titleSeries -}}
{{- .Scratch.Set "titleLang" .Params.titleSeriesLang -}}
{{- .Scratch.Set "titleTr" .Params.titleSeriesTr -}}
{{- .Scratch.Set "schemaType" .Params.schemaTypeSeries -}}
{{- partial "cite.html.tmpl" . -}}
{{- with .Params.numberSeries }}, {{ . | safeHTML -}}{{- end -}}
){{- end -}}</span>
{{- end -}}

View file

@ -2,22 +2,22 @@
{{- erroridf "a11y-chart-longdesc" "No longdesc found for chart '%q' (%q)" ( .Get "chart-id" ) .Page.File.Path -}}
{{- end -}}
<figure class="article__figure figure{{ with .Get "class" }} {{ . }}{{ end }}" role="group">
<figure class="article__figure figure figure--chart{{ with .Get "class" }} {{ . }}{{ end }}" role="group">
{{- with .Get "chart-id" -}}
<canvas class="figure__chart" id="{{ . }}">
You must enable Javascript to view this chart.
</canvas>
<canvas class="chart" id="{{ . }}">
You must enable Javascript to view this chart.
</canvas>
{{- end -}}
{{- with .Get "chart-id-2" -}}
<canvas class="figure__chart" id="{{ . }}">
You must enable Javascript to view this chart.
</canvas>
<canvas class="chart" id="{{ . }}">
You must enable Javascript to view this chart.
</canvas>
{{- end -}}
{{- if or ( .Get "caption" ) ( .Get "title" ) -}}
<figcaption class="figure__caption{{ if not ( or ( .Get "caption" ) ( .Get "title" ) ) }} figure__caption--no-height{{ end }}">
{{- with .Get "title" -}}<h4 class="figcaption__title">{{ . | markdownify | safeHTML }}</h4>{{- end -}}
{{- with .Get "caption" -}}<p class="figcaption__caption">{{ . | markdownify | safeHTML }}</p>{{- end -}}
</figcaption>
<figcaption class="figure__caption{{ if not ( or ( .Get "caption" ) ( .Get "title" ) ) }} figure__caption--no-height{{ end }}">
{{- with .Get "title" -}}<h4 class="figcaption__title">{{ . | markdownify | safeHTML }}</h4>{{- end -}}
{{- with .Get "caption" -}}<p class="figcaption__caption">{{ . | markdownify | safeHTML }}</p>{{- end -}}
</figcaption>
{{- end -}}
</figure>

View file

@ -1,11 +1,28 @@
{{- if .Params.title -}}
{{- if not $.Params.cite -}}
{{- erroridf "missing-cite" "No cite found for citation '%q' (%q)" .Params.title .Page.File.Path -}}
{{- end -}}
{{- else -}}
<!--
Renders a work citation with semantic markup.
@params cite URI for work. Optional.
@params citeStyle Force a citation style. Optional.
@params href URI for citation, or 'asCite' to use value of `cite`. Optional.
@params schemaType The Schema.org `itemtype` value. Default 'CreativeWork'.
@params shortTitle Abbreviated display title. Optional.
@params title Title of the work to display.
@params titleLang Language code of a foreign-language work's title. Optional.
@params titleTr English translation of a foreign-language work's title. Optional.
-->
<!-- Validation -->
{{- if ( not ( isset .Params "title" ) ) -}}
{{- errorf "No title found for citation (%q)" .Page.File.Path -}}
{{- end -}}
{{- $citeID := cond ( .Params.cite | not | not ) .Params.cite .Params.title -}}
{{- if ( not ( isset $.Params "cite" ) ) -}}
{{- erroridf "missing-cite" "No cite found for citation '%q' (%q)" .Params.title .Page.File.Path -}}
{{- end -}}
{{- /**/ -}}{{- partialCached "cite.html" . $citeID -}}{{- /**/ -}}
<!-- Rendering -->
{{- $citationId := cond ( .Params.cite | not | not ) .Params.cite .Params.title -}}
{{- /**/ -}}{{- partialCached "cite.html.tmpl" . $citationId -}}{{- /**/ -}}

View file

@ -1,8 +1,34 @@
{{- $src := $.Page.Resources.GetMatch (.Get "src") -}}
<!--
Shortcode to render a media file as part of content where the place in text flow is not important.
@params src Resource `src` path.
@params link URI or Page Resource to wrap resource in. Optional.
@params rel Force relationship value. Optional.
-->
<!-- Variable assignment -->
{{- $src := $.Page.Resources.GetMatch ( .Get "src" ) -}}
{{- $linkedResource := $.Page.Resources.GetMatch ( .Get "link" ) -}}
{{- $valid_rel_values := partialCached "util/get_valid_rel_values.html.tmpl" . -}}
<!-- Validation -->
{{- if not ( in ( slice "image" "video" ) $src.ResourceType ) -}}
{{- errorf "Resource '%q' resource type '%q' is not valid (%q)" ( .Get "src" ) $src.ResourceType .Page.File.Path -}}
{{- end -}}
{{- if ( not $src ) -}}
{{- errorf "No Page Resource found for src '%q' (%q)" ( .Get "src" ) .Page.File.Path -}}
{{- end -}}
{{- $linkedResource := $.Page.Resources.GetMatch (.Get "link") -}}
{{- with .Get "rel" -}}
{{- if not ( in $valid_rel_values . ) -}}
{{- errorf "Invalid rel value '%q' (%q)" . .Page.File.Path -}}
{{- end -}}
{{- end -}}
<!-- Rendering -->
<figure class="article__figure figure{{ with .Get "class" }} {{ . }}{{ end }}" role="group">
{{- if .Get "link" -}}
@ -14,53 +40,21 @@
{{- end -}}
{{- if eq $src.ResourceType "image" -}}
<picture class="figure__picture"
itemprop="image">
<img class="u-photo figure__image"
{{ if ( or ( eq $src.MediaType.SubType "svg" ) ( eq $src.MediaType.SubType "gif" ) ) }}
src="{{ $src.RelPermalink }}"
{{ else }}
{{ with $src.Resize "1200x webp" }}
src="{{ .RelPermalink }}"
{{ end }}
width="{{ $src.Width }}"
height="{{ $src.Height }}"
{{ end }}
{{- with $src.Params.alt }}
alt="{{ . }}"
{{- end -}}
{{- with $src.Params.title }} title="{{ . }}" {{ end -}}
loading="lazy"
role="img"
/>
</picture>
{{- partial "media/picture.html.tmpl" $src -}}
{{- else if eq $src.ResourceType "video" -}}
{{- if eq $src.MediaType "video/ogg" -}}
<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>
{{- partial "media/audio.html.tmpl" $src -}}
{{- else -}}
<video class="u-video figure__video"
controls
src="{{ $src.RelPermalink }}"
poster="
{{- if $src.Params.poster -}}
{{- $posterSrc := $.Page.Resources.GetMatch ( .Get $src.Params.poster ) -}}
{{- with $posterSrc.Resize "1200x webp" -}}
{{- .RelPermalink -}}
{{- end -}}
{{- else -}}
{{- erroridf "a11y-video-poster" "No poster defined for resource %q (%q)" $src.RelPermalink .Page.File.Path -}}
{{- end -}}
"
itemprop="video">
Your browser doesn't support embedded video, <a href="{{ $src.RelPermalink }}">view the video here</a>.
</video>
{{- partial "media/video.html.tmpl" ( dict "." $src "page_file_path" .Page.File.Path ) -}}
{{- 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 -}}
{{- if or ( .Get "caption" ) ( .Get "title" ) ( $src.Params.attr ) -}}

View file

@ -1,6 +1,6 @@
{{- $src := $.Page.Resources.GetMatch ($.Get 0) -}}
{{- if ( not $src ) -}}
{{- errorf "No Page Resource found for src '%q' (%q)" ( $.Get 0 ) .Page.File.Path -}}
{{- errorf "No Page Resource found for src '%q' (%q).\n\n\tAvailable Page Resources are:\n\t\t%v" ( $.Get 0 ) .Page.File.Path $.Page.Resources -}}
{{- end -}}
{{- with $src -}}

View file

@ -0,0 +1,45 @@
<!--
Shortcode to render an image as part of content where the place in text flow is important.
@params src Image `src` path.
@params link URI or Page Resource to wrap image in. Optional.
@params rel Force relationship value. Optional.
-->
<!-- Variable assignment -->
{{- $src := $.Page.Resources.GetMatch ( .Get "src" ) -}}
{{- $linkedResource := $.Page.Resources.GetMatch ( .Get "link" ) -}}
{{- $valid_rel_values := partialCached "util/get_valid_rel_values.html.tmpl" . -}}
<!-- Validation -->
{{- if ( not $src ) -}}
{{- errorf "No Page Resource found for src %q (%q)" ( .Get "src" ) .Page.File.Path -}}
{{- end -}}
{{- if not ( eq $src.ResourceType "image" ) -}}
{{- errorf "Resource %q has resource type %q (expected \"image\") (%q)" ( .Get "src" ) $src.ResourceType .Page.File.Path -}}
{{- end -}}
{{- with .Get "rel" -}}
{{- if not ( in $valid_rel_values . ) -}}
{{- errorf "Invalid rel value %q (%q)" . .Page.File.Path -}}
{{- end -}}
{{- end -}}
<!-- Rendering -->
{{- if .Get "link" -}}
{{- if $linkedResource -}}
<a href="{{- $linkedResource.RelPermalink -}}"{{- with .Get "rel" }} rel="{{- . -}}"{{- end -}}>
{{- else -}}
<a href="{{- .Get "link" -}}">
{{- end -}}
{{- end -}}
{{- partial "media/picture.html.tmpl" $src -}}
{{- if .Get "link" -}}
</a>
{{- end -}}

View file

@ -0,0 +1,47 @@
<!--
Shortcode to render a video as part of content where the place in text flow is important.
@params src Video `src` path.
@params link URI or Page Resource to wrap video in. Optional.
@params rel Force relationship value. Optional.
-->
<!-- Variable assignment -->
{{- $src := $.Page.Resources.GetMatch ( .Get "src" ) -}}
{{- $linkedResource := $.Page.Resources.GetMatch ( .Get "link" ) -}}
{{- $valid_rel_values := partialCached "util/get_valid_rel_values.html.tmpl" . -}}
<!-- Validation -->
{{- if ( not $src ) -}}
{{- errorf "No Page Resource found for src %q (%q)" ( .Get "src" ) .Page.File.Path -}}
{{- end -}}
{{- if not ( eq $src.ResourceType "video" ) -}}
{{- errorf "Resource %q has resource type %q (expected \"video\") (%q)" ( .Get "src" ) $src.ResourceType .Page.File.Path -}}
{{- else if ( eq $src.MediaType "video/ogg" ) -}}
{{- errorf "Resource %q has 'video/ogg' media type %q (expected \"video/webm\" or other video type) (%q)" ( .Get "src" ) $src.MediaType .Page.File.Path -}}
{{- end -}}
{{- with .Get "rel" -}}
{{- if not ( in $valid_rel_values . ) -}}
{{- errorf "Invalid rel value %q (%q)" . .Page.File.Path -}}
{{- end -}}
{{- end -}}
<!-- Rendering -->
{{- if .Get "link" -}}
{{- if $linkedResource -}}
<a href="{{- $linkedResource.RelPermalink -}}"{{- with .Get "rel" }} rel="{{- . -}}"{{- end -}}>
{{- else -}}
<a href="{{- .Get "link" -}}">
{{- end -}}
{{- end -}}
{{- partial "media/video.html.tmpl" ( dict "." $src "page_file_path" .Page.File.Path ) -}}
{{- if .Get "link" -}}
</a>
{{- end -}}