From fef60c6e4325cb2f49e52a01b7c6dab96b010ef3 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Thu, 24 Oct 2024 12:00:02 +0200 Subject: [PATCH] Add generic code to build album of all images --- assets/js/gallery.js | 36 ++++++++++++++++++++++++ layouts/_default/list.json | 0 layouts/albums/list.html | 32 +++++++++++++++++++++ layouts/partials/albums/breadcrumbs.html | 8 ++++++ layouts/partials/albums/images.json | 30 ++++++++++++++------ layouts/partials/footer.html | 1 + layouts/partials/head/css.html | 21 ++++++++++---- layouts/partials/head/js.html | 4 +++ layouts/partials/header.html | 3 +- 9 files changed, 118 insertions(+), 17 deletions(-) create mode 100644 assets/js/gallery.js create mode 100644 layouts/_default/list.json create mode 100644 layouts/albums/list.html create mode 100644 layouts/partials/albums/breadcrumbs.html diff --git a/assets/js/gallery.js b/assets/js/gallery.js new file mode 100644 index 0000000..6177906 --- /dev/null +++ b/assets/js/gallery.js @@ -0,0 +1,36 @@ +$(function(){ + $.get('./index.json', function(data) { + var items = $.map(data.images, function(img) { + return { + src: img.url, + srct: img.thumbnail, + height: img.height, + width: img.width, + } + }); + + $('#gallery').nanogallery2({ + thumbnailHeight: 200, + thumbnailWidth: 'auto', + + thumbnailGutterWidth: 10, + thumbnailGutterHeight: 10, + + thumbnailDisplayTransition: 'scaleUp', + thumbnailDisplayTransitionDuration: 700, + + thumbnailHoverEffect2: 'toolsAppear|scale120|borderLighter', + + // thumbnailToolbarImage: { + // topLeft: 'share|download', + // }, + + viewerGallery: 'bottom', + viewerTools: { + topRight: 'zoomButton, fullscreenButton, downloadButton, closeButton', + }, + + items, + }) + }) +}) diff --git a/layouts/_default/list.json b/layouts/_default/list.json new file mode 100644 index 0000000..e69de29 diff --git a/layouts/albums/list.html b/layouts/albums/list.html new file mode 100644 index 0000000..5d037b8 --- /dev/null +++ b/layouts/albums/list.html @@ -0,0 +1,32 @@ +{{ define "main" }} +

{{ .Title }}

+ {{ partial "albums/breadcrumbs.html" . }} + {{ .Content }} +
+ {{ range .Pages.GroupBy "Weight" }} + {{ range .Pages.ByTitle }} + +
+ {{ $sa := . }} + {{ with .Params.teaserImage }} + {{ $img := $sa.Resources.Get . }} + {{ $sa.Title }} + {{ else }} + {{ warnf "Could not find teaser image for %s" .RelPermalink }} + + {{ end }} +
+
{{ .Title }}
+
+ {{ end }} + {{ end }} +
+
+ {{ with .Resources.Get "album.zip" }} + + {{ end }} + +
+{{ end }} diff --git a/layouts/partials/albums/breadcrumbs.html b/layouts/partials/albums/breadcrumbs.html new file mode 100644 index 0000000..307e715 --- /dev/null +++ b/layouts/partials/albums/breadcrumbs.html @@ -0,0 +1,8 @@ +{{ with .Ancestors }} + +{{ end }} diff --git a/layouts/partials/albums/images.json b/layouts/partials/albums/images.json index 7622118..cd6d0d2 100644 --- a/layouts/partials/albums/images.json +++ b/layouts/partials/albums/images.json @@ -1,12 +1,24 @@ {{- $first := true -}} +{{- $filter := images.AutoOrient -}} +{{- $teaser := "" -}} +{{- with .Params.teaserImage -}} + {{- $teaser = $.Resources.GetMatch . -}} +{{- end -}} {{- range .Resources.ByType "image" -}} -{{- if not $first }}, {{ end }} -{{ $first = false -}} -{ - "title": "{{ .Title }}", - "url": "{{ .RelPermalink }}", - "width": "{{ .Width }}", - "height": "{{ .Height }}", - "thumbnail": "{{ (.Fit "200x200").RelPermalink }}" -} + {{- if not (eq $teaser .) -}} + {{- if not $first }}, {{ end }} + {{ $first = false -}} + {{- with . | images.Filter $filter -}} + { + "title": "{{ .Title }}", + "url": "{{ .RelPermalink }}", + "width": "{{ .Width }}", + "height": "{{ .Height }}", + "thumbnail": "{{ (.Fit "300x200").RelPermalink }}" + } + {{- end -}} + {{- else -}} + {{ warnf "Skipping teaser image" }} + {{- end -}} + {{ end -}} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index a7cd916..6778d89 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -1 +1,2 @@

Copyright {{ now.Year }}. All rights reserved.

+

Impressum

diff --git a/layouts/partials/head/css.html b/layouts/partials/head/css.html index 91b928d..6808918 100644 --- a/layouts/partials/head/css.html +++ b/layouts/partials/head/css.html @@ -1,9 +1,18 @@ -{{- with resources.Get "css/main.css" }} - {{- if eq hugo.Environment "development" }} - - {{- else }} - {{- with . | minify | fingerprint }} - +{{- with resources.Get "css/main.scss" }} + {{- $sassOptions := dict "targetPath" "css/style.css" "outputStyle" (cond hugo.IsProduction "compressed" "nested") "enableSourceMap" (not hugo.IsProduction) "transpiler" "dartsass" -}} + {{- with . | css.Sass $sassOptions -}} + {{- if hugo.IsProduction }} + {{- with . | minify | fingerprint }} + + {{- end }} + {{- else }} + {{- end }} {{- end }} {{- end }} +{{ with (resources.Get "css/nanogallery2.min.css" | fingerprint ) }} + +{{ end}} +{{ with (resources.Get "css/nanogallery2.woff.min.css" | fingerprint ) }} + +{{ end}} diff --git a/layouts/partials/head/js.html b/layouts/partials/head/js.html index 18fe842..da2625c 100644 --- a/layouts/partials/head/js.html +++ b/layouts/partials/head/js.html @@ -10,3 +10,7 @@ {{- end }} {{- end }} {{- end }} + + + + diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 7980a00..124722f 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -1,2 +1 @@ -

{{ site.Title }}

-{{ partial "menu.html" (dict "menuID" "main" "page" .) }} +

{{site.Title }}