Files
hugo-snap-gallery/layouts/shortcodes/snap-gallery.html

35 lines
1.2 KiB
HTML
Raw Normal View History

{{/* Count number of gallery on page */}}
{{- $.Page.Scratch.Add "gallerycount" 1 -}}
{{ $galno := $.Page.Scratch.Get "gallerycount" }}
2024-01-30 12:18:28 +01:00
{{/* Initialise variables holding image paths */}}
2024-01-30 12:18:28 +01:00
{{ $imgs := slice }}
2024-01-30 12:34:00 +01:00
{{/* Get/sanitise image paths */}}
2024-01-30 12:18:28 +01:00
{{ if .Params.isdir }}
2024-01-30 12:29:32 +01:00
{{/* Get images from folder, put into map */}}
{{ $imgdir := print "/static/" .Params.src }}
{{- range readDir $imgdir -}}
{{ $imgs = $imgs | append (print $.Params.src "/" .Name ) }}
{{ end }}
2024-01-30 12:18:28 +01:00
{{ else }}
2024-01-30 12:29:32 +01:00
{{/* Get images from src Param, separated by comma */}}
2024-01-30 12:18:28 +01:00
{{ range (split .Params.src ",") }}
{{ $imgs = $imgs | append (trim . " ") }}
{{ end }}
{{ end }}
{{/* Visible images in gallery mode */}}
{{ partial "gallery" (dict "columns" .Params.columns "minwidth" .Params.minwidth "imgs" $imgs "galno" $galno) }}
2024-01-30 12:18:28 +01:00
{{/* The Modal/Lightbox */}}
2024-02-01 15:10:31 +01:00
{{ partial "lightbox" (dict "galno" $galno "imgs" $imgs) }}
{{/* Load CSS/JS and make sure it is only loaded once */}}
{{- if eq ($.Page.Scratch.Get "gallerycount") 1 }}
{{- with resources.Get "scss/snap-gallery.scss" | toCSS }}
<link rel="stylesheet" href="{{ .RelPermalink }}" crossorigin="anonymous">
{{- end }}
2024-01-30 22:47:35 +01:00
<script src="/js/snap-gallery.js"></script>
{{ end }}