From e20fb7c1056fd84b7179c824ee202b337d8129fb Mon Sep 17 00:00:00 2001 From: Sped0n Date: Mon, 30 Oct 2023 15:58:37 +0800 Subject: [PATCH] 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. --- layouts/partials/resources/imageJSON.html | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 layouts/partials/resources/imageJSON.html diff --git a/layouts/partials/resources/imageJSON.html b/layouts/partials/resources/imageJSON.html new file mode 100644 index 0000000..fd29203 --- /dev/null +++ b/layouts/partials/resources/imageJSON.html @@ -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 -}} + +{{- end -}}