refactor: resource attribution
This commit is contained in:
parent
1a61aeade0
commit
24bfa733ba
12 changed files with 169 additions and 99 deletions
58
layouts/partials/media/attr.html
Normal file
58
layouts/partials/media/attr.html
Normal file
|
@ -0,0 +1,58 @@
|
|||
<!--
|
||||
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 }} (
|
||||
{{- with ( index .sc.Site.Data.licences $attr_licence ) -}}
|
||||
<a href="{{ . }}" target="_blank" rel="noopener">
|
||||
{{- end -}}
|
||||
{{- $attr_licence -}}
|
||||
{{- with ( index .sc.Site.Data.licences $attr_licence ) -}}
|
||||
</a>
|
||||
{{- end -}}
|
||||
)
|
||||
{{- end -}}
|
||||
<p>
|
|
@ -9,28 +9,30 @@
|
|||
{{- $src := . -}}
|
||||
{{- $isResizable := not ( in ( slice "svg" "gif" ) $src.MediaType.SubType ) -}}
|
||||
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<picture
|
||||
class="picture"
|
||||
itemprop="image"
|
||||
>
|
||||
{{ if $isResizable -}}
|
||||
<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"
|
||||
<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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue