update
This commit is contained in:
parent
187900fd5b
commit
1fd9adcb52
23 changed files with 1800 additions and 98 deletions
45
layouts/shortcodes/picture.html
Normal file
45
layouts/shortcodes/picture.html
Normal 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 -}}
|
Loading…
Add table
Add a link
Reference in a new issue