feat(imageJSON.html): add imageJSON.html partial template to generate JSON data for image resources

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.
This commit is contained in:
Sped0n
2023-10-30 15:58:37 +08:00
parent 2553c7e1fc
commit e20fb7c105

View File

@@ -0,0 +1,18 @@
{{- $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 -}}