mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-14 10:09:31 -07:00
The imageJSON.html partial template has been added to the layouts/partials/resources directory. This template generates JSON data for image resources on a page. It retrieves the page context and the gallery resources using the site.GetPage and .Resources.ByType functions. It then iterates over the image resources, resizing them and adding their information to a Scratch variable. Finally, it outputs the JSON data as a script tag with the id "imagesSource". This JSON data can be used to dynamically load and display images on the page.
19 lines
568 B
HTML
19 lines
568 B
HTML
{{- $Page := .Page -}}
|
|
|
|
{{ $gallery := site.GetPage .Path }}
|
|
{{ with $gallery.Resources.ByType "image" }}
|
|
{{ $index := len . }}
|
|
{{ $Page.Scratch.Add "img" slice }}
|
|
{{ range . }}
|
|
{{ $index = sub $index 1 }}
|
|
{{ $resize := .Resize "x2000 webp Lanczos q70" }}
|
|
{{ $Page.Scratch.Add "img" (dict
|
|
"index" (int $index)
|
|
"url" (string .RelPermalink)
|
|
"imgH" (int .Height)
|
|
"imgW" (int .Width))
|
|
}}
|
|
{{- end -}}
|
|
<script id="imagesSource" type="application/json">{{ $Page.Scratch.Get "img" | jsonify | safeJS }}</script>
|
|
{{- end -}}
|