Skip to content

Commit 9c72f04

Browse files
committed
Allow images to be passed in as a slice
Fixes #21
1 parent 3bed884 commit 9c72f04

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

‎layouts/partials/gallerydeluxe/init.html‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
1-
{{ $sourcePath := .sourcePath | default "images" }}
2-
{{ $gallery := site.GetPage $sourcePath }}
1+
{{/* init.hmlt takes either a slice of .images or a .sourcePath that points to a bundle with images.
2+
An .id will be calculated if not provided. This will be used to create the URL to the data file.
3+
*/}}
4+
5+
{{ $images := slice }}
6+
{{ $galleryIDBase := .id }}
7+
{{ with .images }}
8+
{{ $images = . }}
9+
{{ if not $galleryIDBase }}
10+
{{ range $images }}
11+
{{ $galleryIDBase = printf "%s%s" $galleryIDBase .RelPermalink }}
12+
{{ end }}
13+
{{ end }}
14+
{{ else }}
15+
{{ $sourcePath := .sourcePath | default "images" }}
16+
{{ if not $galleryIDBase }}
17+
{{ $galleryIDBase = $sourcePath }}
18+
{{ end }}
19+
{{ $gallery := site.GetPage $sourcePath }}
20+
{{ $images = $gallery.Resources.ByType "image" }}
21+
{{ end }}
22+
{{ $galleryID := $galleryIDBase | crypto.FNV32a }}
323
{{ $imageDataUrl := "" }}
424
{{ $s := slice }}
525
{{ $params := site.Params.gallerydeluxe }}
6-
{{ with $gallery.Resources.ByType "image" }}
26+
{{ with $images }}
727
{{ range . }}
828
{{ $thumbs := partial "gallerydeluxe/create-thumbs.html" . }}
929
{{ $20 := (index $thumbs "20") }}
@@ -40,13 +60,13 @@
4060
}}
4161
{{ $s = $s | append $m }}
4262
{{ end }}
43-
{{ $r := $s | jsonify | resources.FromString (printf "%s-gallery.json" $sourcePath) }}
63+
{{ $r := $s | jsonify | resources.FromString (printf "%d-gallery.json" $galleryID ) }}
4464
{{ if hugo.IsProduction }}
4565
{{ $r = $r | minify | fingerprint }}
4666
{{ end }}
4767
{{ $imageDataUrl = $r.RelPermalink }}
4868
{{ else }}
49-
{{ errorf "gallerydeluxe: No bundle found in %q. sourcePath must be set to a valid Hugo bundle with JPG images in it." $sourcePath }}
69+
{{ errorf "gallerydeluxe: No images provided. Either 'images' as as slice of images or 'sourcePath' must be set to point to a valid Hugo bundle with JPG images in it." }}
5070
{{ end }}
5171

5272
{{ return (dict

0 commit comments

Comments
 (0)