This commit is contained in:
Julieñ
2024-05-21 09:41:48 +02:00
parent 4c356a8af2
commit 1bb184cfe4
1646 changed files with 3456 additions and 1 deletions
@@ -0,0 +1,44 @@
{{/* 20, 100, 250, and 500 height */}}
{{ $full := . }}
{{ with site.Params.gallerydeluxe.watermark }}
{{ $opts := . }}
{{ with resources.Get .image }}
{{ $watermark := . }}
{{ $fullWidth := $full.Width }}
{{ $watermarkMaxWidth := div $fullWidth 6 }}
{{ if gt $watermark.Width $watermarkMaxWidth }}
{{ $watermark = $watermark.Resize (printf "%dx" $watermarkMaxWidth) }}
{{ end }}
{{ $watermarkWidth := $watermark.Width }}
{{ $watermarkHeight := $watermark.Height }}
{{ $posx := $opts.posx | default "right" }}
{{ $posy := $opts.posy | default "bottom" }}
{{ $padding := 20 }}
{{ $x := $padding }}
{{ $y := $padding }}
{{ if eq $posx "center" }}
{{ $x = div $fullWidth 2 }}
{{ $x = sub $x (div $watermarkWidth 2) }}
{{ end }}
{{ if eq $posy "center" }}
{{ $y = div $full.Height 2 }}
{{ $y = sub $y (div $watermarkHeight 2) }}
{{ end }}
{{ if eq $posx "right" }}
{{ $x = sub $fullWidth (add $watermarkWidth $padding) }}
{{ end }}
{{ if eq $posy "bottom" }}
{{ $y = sub $full.Height (add $watermarkHeight $padding) }}
{{ end }}
{{ $full = $full.Filter (images.Overlay $watermark $x $y ) }}
{{ end }}
{{ end }}
{{ $m := dict
"full" $full
"20" (.Resize "x20")
"100" (.Resize "x100")
"250" (.Resize "x250")
"500" (.Resize "x500")
}}
{{ return $m }}
@@ -0,0 +1,9 @@
{{ $js := resources.Get "js/gallerydeluxe/cdn/index.js" }}
{{ $js = $js | js.Build (dict "params" site.Params.gallerydeluxe "minify" hugo.IsProduction) }}
{{ $styles := resources.Get "css/gallerydeluxe/styles.css" }}
{{ if hugo.IsProduction}}
{{ $js = $js | fingerprint }}
{{ $styles = $styles | minify | fingerprint }}
{{ end }}
<script src="{{ $js.RelPermalink }}" defer></script>
<link rel="stylesheet" href="{{ $styles.RelPermalink }}"></link>
@@ -0,0 +1,76 @@
{{/* init.hmlt takes either a slice of .images or a .sourcePath that points to a bundle with images.
An .id will be calculated if not provided. This will be used to create the URL to the data file.
*/}}
{{ $images := slice }}
{{ $galleryIDBase := .id }}
{{ with .images }}
{{ $images = . }}
{{ if not $galleryIDBase }}
{{ range $images }}
{{ $galleryIDBase = printf "%s%s" $galleryIDBase .RelPermalink }}
{{ end }}
{{ end }}
{{ else }}
{{ $sourcePath := .sourcePath | default "images" }}
{{ if not $galleryIDBase }}
{{ $galleryIDBase = $sourcePath }}
{{ end }}
{{ $gallery := site.GetPage $sourcePath }}
{{ $images = $gallery.Resources.ByType "image" }}
{{ end }}
{{ $galleryID := $galleryIDBase | crypto.FNV32a }}
{{ $imageDataUrl := "" }}
{{ $s := slice }}
{{ $params := site.Params.gallerydeluxe }}
{{ with $images }}
{{ range . }}
{{ $thumbs := partial "gallerydeluxe/create-thumbs.html" . }}
{{ $full := $thumbs.full }}
{{ $20 := (index $thumbs "20") }}
{{ $colors := slice }}
{{ $exif := dict }}
{{ if $params.enable_exif }}
{{/* Workaround for https://github.com/gohugoio/hugo/issues/10345 */}}
{{ $tags := newScratch }}
{{ range $k, $v := .Exif.Tags }}
{{ $tags.Set $k $v }}
{{ end }}
{{ $exif = dict
"Tags" $tags.Values
"Date" .Exif.Date
"Lat" .Exif.Lat
"Long" .Exif.Long
}}
{{ end }}
{{ if (ge hugo.Version "0.104") }}
{{/* .Colors method was added in Hugo 0.104.0 */}}
{{ $colors = $20.Colors }}
{{ end }}
{{ $m := dict
"name" .Name
"full" $full.RelPermalink
"exif" $exif
"width" $full.Width
"height" $full.Height
"colors" $colors
"20" $20.RelPermalink
"100" (index $thumbs "100").RelPermalink
"250" (index $thumbs "250").RelPermalink
"500" (index $thumbs "500").RelPermalink
}}
{{ $s = $s | append $m }}
{{ end }}
{{ $r := $s | jsonify | resources.FromString (printf "%d-gallery.json" $galleryID ) }}
{{ if hugo.IsProduction }}
{{ $r = $r | minify | fingerprint }}
{{ end }}
{{ $imageDataUrl = $r.RelPermalink }}
{{ else }}
{{ 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." }}
{{ end }}
{{ return (dict
"imageDataUrl" $imageDataUrl
)
}}