Allow changing of gallery image size

This commit is contained in:
Christian Wolf 2025-02-22 17:31:52 +01:00
parent c16b3ab59f
commit 945a114f08
3 changed files with 21 additions and 2 deletions

View File

@ -10,7 +10,7 @@ $(function(){
}); });
$('#gallery').nanogallery2({ $('#gallery').nanogallery2({
thumbnailHeight: 200, thumbnailHeight: galleryUseHeight,
thumbnailWidth: 'auto', thumbnailWidth: 'auto',
thumbnailGutterWidth: 10, thumbnailGutterWidth: 10,

View File

@ -1,6 +1,15 @@
{{- $first := true -}} {{- $first := true -}}
{{- $filter := images.AutoOrient -}} {{- $filter := images.AutoOrient -}}
{{- $teaser := .Resources.GetMatch "thumbnail.jpg" -}} {{- $teaser := .Resources.GetMatch "thumbnail.jpg" -}}
{{- $galleryHeight := 200 }}
{{- with site.Params.galleryUseHeight }}
{{- $galleryHeight = . | int }}
{{- end }}
{{- with .Page.Params.galleryUseHeight }}
{{- $galleryHeight = . | int }}
{{- end }}
{{- $galleryWidth := mul $galleryHeight 1.5 | math.Round | int -}}
{{- $gallerySize := printf "%dx%d" $galleryWidth $galleryHeight -}}
{{- range .Resources.ByType "image" -}} {{- range .Resources.ByType "image" -}}
{{- if not (eq $teaser .) -}} {{- if not (eq $teaser .) -}}
{{- if not $first }}, {{ end }} {{- if not $first }}, {{ end }}
@ -11,7 +20,7 @@
"url": "{{ .RelPermalink }}", "url": "{{ .RelPermalink }}",
"width": "{{ .Width }}", "width": "{{ .Width }}",
"height": "{{ .Height }}", "height": "{{ .Height }}",
"thumbnail": "{{ (.Fit "300x200").RelPermalink }}" "thumbnail": "{{ (.Fit $gallerySize).RelPermalink }}"
} }
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}

View File

@ -13,4 +13,14 @@
<!-- <script src="{{ .Page.Site.BaseURL }}/js/main.js" defer></script> --> <!-- <script src="{{ .Page.Site.BaseURL }}/js/main.js" defer></script> -->
<script src="{{ (resources.Get "js/jquery.min.js").RelPermalink }}"></script> <script src="{{ (resources.Get "js/jquery.min.js").RelPermalink }}"></script>
<script src="{{ (resources.Get "js/jquery.nanogallery2.min.js").RelPermalink }}" defer></script> <script src="{{ (resources.Get "js/jquery.nanogallery2.min.js").RelPermalink }}" defer></script>
<script>
{{- $galleryHeight := 200 }}
{{- with site.Params.galleryUseHeight }}
{{- $galleryHeight = . }}
{{- end }}
{{- with .Page.Params.galleryUseHeight }}
{{- $galleryHeight = . }}
{{- end }}
var galleryUseHeight = {{ $galleryHeight }};
</script>
<script src="{{ (resources.Get "/js/gallery.js").RelPermalink }}" defer></script> <script src="{{ (resources.Get "/js/gallery.js").RelPermalink }}" defer></script>