mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-14 10:09:31 -07:00
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:
18
layouts/partials/resources/imageJSON.html
Normal file
18
layouts/partials/resources/imageJSON.html
Normal 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 -}}
|
||||
Reference in New Issue
Block a user