support providing a metadata file
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
{{- $imgs := .imgs -}}
|
||||
{{- $galno := .galno -}}
|
||||
<div class="snap-gallery" style="--columns:{{ default 4 .columns }};--min-width:{{ default "200px" .minwidth }};--gap:10px;--cursor:{{ .cursor }};--aspectratio:{{ safeCSS (default "16/10" .aspectratio) }};">
|
||||
{{- range $i, $img := $imgs -}}
|
||||
{{- range $i, $img := $imgs }}
|
||||
<div class="snap-image">
|
||||
<img src="{{ $img }}" onclick="openLightbox({{ $galno }});openLightboxItem({{ $galno }}, {{ add $i 1 }});">
|
||||
<img
|
||||
src="{{ relURL $img.src }}"
|
||||
{{ range $attr, $value := $img.html -}}
|
||||
{{ safeHTMLAttr $attr }}={{ $value }}
|
||||
{{ end -}}
|
||||
onclick="openLightbox({{ $galno }});openLightboxItem({{ $galno }}, {{ add $i 1 }});" />
|
||||
</div>
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
</div>
|
||||
|
||||
@@ -4,7 +4,12 @@
|
||||
{{- range $i, $img := $imgs }}
|
||||
<div class="snap-lightbox-inner">
|
||||
<div class="numbertext">{{ add $i 1 }} / {{ len $imgs }}</div>
|
||||
<img src="{{ $img }}" style="width:100%">
|
||||
<img
|
||||
src="{{ relURL $img.src }}"
|
||||
{{ range $attr, $value := $img.html -}}
|
||||
{{ safeHTMLAttr $attr }}={{ $value }}
|
||||
{{ end -}}
|
||||
/>
|
||||
</div>
|
||||
{{- end -}}
|
||||
|
||||
|
||||
@@ -4,9 +4,14 @@
|
||||
{{- range $i, $img := $imgs }}
|
||||
<div class="snap-image">
|
||||
<div class="numbertext">{{ add $i 1 }} / {{ len $imgs }}</div>
|
||||
<img src="{{ $img }}" onclick="openLightbox({{ $galno }});openLightboxItem({{ $galno }}, {{ add $i 1 }});">
|
||||
<img
|
||||
src="{{ relURL $img.src }}"
|
||||
{{ range $attr, $value := $img.html -}}
|
||||
{{ safeHTMLAttr $attr }}={{ $value }}
|
||||
{{ end -}}
|
||||
onclick="openLightbox({{ $galno }});openLightboxItem({{ $galno }}, {{ add $i 1 }});" />
|
||||
</div>
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
|
||||
<a class="snap-prev" onclick="moveSlideshowItem({{ $galno }}, -1)"><span>❮</span></a>
|
||||
<a class="snap-next" onclick="moveSlideshowItem({{ $galno }}, 1)"><span>❯</span></a>
|
||||
|
||||
@@ -18,6 +18,12 @@
|
||||
{{- $imgs := slice -}}
|
||||
{{- $img_exts := slice ".jpg" ".jpeg" ".png" ".gif" ".webp" ".tiff" -}}
|
||||
|
||||
{{/* Get information from optional metadata file */}}
|
||||
{{- $metadata := dict -}}
|
||||
{{- with .Params.metadata -}}
|
||||
{{- $metadata = index $.Site.Data . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Get images from src Param, separated by comma */}}
|
||||
{{- range (split .Params.src ",") -}}
|
||||
{{- $img := (trim . " ") -}}
|
||||
@@ -36,10 +42,19 @@
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Filter collected files by whether they are an image. Throw others out */}}
|
||||
{{/* Filter collected files, store them as slice of dicts/maps */}}
|
||||
{{- range $imgs_collect -}}
|
||||
{{/* Only process files if they are recognised as an image */}}
|
||||
{{- if in $img_exts (lower (path.Ext .)) -}}
|
||||
{{- $imgs = $imgs | append . -}}
|
||||
{{/* Create a dict holding path and optional metadata */}}
|
||||
{{- $imgdict := dict "src" . -}}
|
||||
{{/* If metadata for this image path found, add all of it to dict */}}
|
||||
{{- $img_metadata := where $metadata "src" . -}}
|
||||
{{- with $img_metadata -}}
|
||||
{{- $imgdict = merge $imgdict (index . 0) -}}
|
||||
{{- end -}}
|
||||
{{/* Add final dict to slice */}}
|
||||
{{- $imgs = $imgs | append $imgdict -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
@@ -63,6 +78,6 @@
|
||||
{{- end -}}
|
||||
|
||||
{{/* The Modal/Lightbox */}}
|
||||
{{- if $lightbox -}}
|
||||
{{ if $lightbox -}}
|
||||
{{- partial "lightbox" (dict "galno" $galno "imgs" $imgs) -}}
|
||||
{{- end -}}
|
||||
|
||||
Reference in New Issue
Block a user