Files
bridget/layouts/_default/single.json
Spedon 9b08d255f1 Use JSON file to replace raw string in DOM (#147)
* chore(Geist): bump geist font to v1.0.1

* refactor(_typography.scss): split the CSS lang tag to ensure compatibility with Chromium-based browsers

* refactor(stage.ts): bump up preload count on desktop

* feat(params.toml): add support for user defined resize option

* feat(_fonts.scss): add a new font file to better support fullwidth plus and minus

* refactor(info): update info

* chore(build.yml): update branch name for updating bundled artifacts to include the current date

* chore(package.json): update version from 0.0.1 to v0.0.2 to reflect changes made in the codebase

* feat: refactor initialization process for retrieving and sorting image data

- Modify `main.ts` to use async initialization of resources
- Change the return type of `initResources` function to `Promise<ImageJSON[]>`
- Add try-catch block to handle errors in `initResources` function
- Use fetch API to retrieve image data from `index.json`
- Sort the image data based on the index field

* refactor: update file naming and variable assignments in layouts

- Add new file `exampleSite/config/_default/outputs.toml` with the contents `page = ["HTML", "JSON"]`
- Rename file `layouts/partials/resources/imageJSON.html` to `layouts/_default/single.json`
- Modify variable assignments and references in the `single.json` layou

* chore: remove code that includes imageJSON.html partials in layouts

- Remove the code that includes the "resources/imageJSON.html" partial in the 404.html layout
- Remove the code that includes the "resources/imageJSON.html" partial in the single.html layout
2023-11-13 20:51:08 +08:00

38 lines
1.1 KiB
JSON

{{- $Page := . -}}
{{- $Path := "" -}}
{{- $params := .Page.Params | merge .Site.Params.Page -}}
{{- with partial "function/currentMenuItem.html" . -}}
{{- $Path = .DirName -}}
{{- end -}}
{{- $gallery := site.GetPage $Path -}}
{{- with $gallery.Resources.ByType "image" -}}
{{- $index := len . -}}
{{- $Page.Scratch.Add "img" slice -}}
{{- range sort . "Name" "desc" -}}
{{- $image := . -}}
{{- $index = sub $index 1 -}}
{{- $alt := .Name -}}
{{- with $params.unifiedAlt -}}
{{- $alt = . -}}
{{- end -}}
{{- $lores := .Resize (site.Params.loResOpt | default "700x webp Lanczos q60") -}}
{{- $hires := .Resize (site.Params.hiResOpt | default "2000x webp Lanczos q75") -}}
{{- $Page.Scratch.Add "img" (dict
"index" (int $index)
"alt" (string $alt)
"loUrl" (string $lores.RelPermalink)
"loImgH" (int $lores.Height)
"loImgW" (int $lores.Width)
"hiUrl" (string $hires.RelPermalink)
"hiImgH" (int $hires.Height)
"hiImgW" (int $hires.Width)
)
-}}
{{- end -}}
{{ $Page.Scratch.Get "img" | jsonify }}
{{- else -}}
[]
{{- end -}}