1

Résout les images référencées par des métadonnées YAML

This commit is contained in:
2026-03-23 23:12:55 +01:00
parent e11e4ee591
commit 99f674dd9f
9 changed files with 234 additions and 86 deletions

View File

@@ -3,15 +3,23 @@
{{- $coverPath := .Params.cover -}}
{{- $img := false -}}
{{- if $coverPath -}}
{{- if strings.HasSuffix $coverPath ".yaml" -}}
{{- $coverAbsPath := printf "%s%s" $page.File.Dir $coverPath -}}
{{- $coverRaw := readFile $coverAbsPath -}}
{{- $coverData := $coverRaw | transform.Unmarshal -}}
{{- with $coverData.file -}}
{{- $img = $page.Resources.GetMatch . -}}
{{- $coverResourcePath := (urls.Parse $coverPath).Path -}}
{{- if ne $coverResourcePath "" -}}
{{- $coverPathLower := lower $coverResourcePath -}}
{{- if or (strings.HasSuffix $coverPathLower ".yaml") (strings.HasSuffix $coverPathLower ".yml") -}}
{{- $coverDataFile := $page.Resources.Get $coverResourcePath -}}
{{- if $coverDataFile -}}
{{- with $coverDataFile.Content | transform.Unmarshal -}}
{{- with index . "file" -}}
{{- $coverFilePath := strings.TrimSpace (printf "%v" .) -}}
{{- if ne $coverFilePath "" -}}
{{- $img = $page.Resources.Get $coverFilePath -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- $img = $page.Resources.GetMatch $coverPath -}}
{{- $img = $page.Resources.Get $coverResourcePath -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if $img -}}

View File

@@ -1,18 +1,37 @@
{{- $imgPath := .Destination -}}
{{- $imgPath := (urls.Parse .Destination).Path -}}
{{- $imgName := path.Base $imgPath | replaceRE "\\.[^.]+$" "" -}} {{/* Supprime l'extension */}}
{{- $dataPath := printf "data/images/%s.yaml" $imgName -}}
{{- $dataFile := .Page.Resources.Get $dataPath -}}
{{- $data := dict -}}
{{- if $dataFile }}
{{- $data = $dataFile.Content | transform.Unmarshal -}}
{{- with $dataFile.Content | transform.Unmarshal -}}
{{- $data = . -}}
{{- end -}}
{{- end }}
{{- $alt := .PlainText | default $data.title | default "" -}}
{{- $title := .Title | default $data.title | default .Page.Title -}}
{{- $description := default $data.description | default $title -}}
{{- $image := .Page.Resources.GetMatch $imgPath -}}
{{- $display := $image }}
{{- $image := false -}}
{{- $imagePathLower := lower $imgPath -}}
{{- if or (strings.HasSuffix $imagePathLower ".yaml") (strings.HasSuffix $imagePathLower ".yml") -}}
{{- $imageDataFile := .Page.Resources.Get $imgPath -}}
{{- if $imageDataFile -}}
{{- with $imageDataFile.Content | transform.Unmarshal -}}
{{- with index . "file" -}}
{{- $imageFilePath := strings.TrimSpace (printf "%v" .) -}}
{{- if ne $imageFilePath "" -}}
{{- $image = $.Page.Resources.Get $imageFilePath -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- $image = .Page.Resources.Get $imgPath -}}
{{- end -}}
{{- with $image -}}
{{- $resolvedImage := . -}}
{{- $display := $resolvedImage }}
{{- if and $display (ne $display.MediaType.SubType "svg") (gt $display.Height 810) }}
{{- $display = $image.Resize "x810" -}}
{{- $display = $resolvedImage.Resize "x810" -}}
{{- end }}
<figure>
{{- with $description }}
@@ -20,7 +39,7 @@
<p>{{ . | markdownify }}</p>
</figcaption>
{{- end }}
<a href="{{ $image.RelPermalink }}" title="Cliquez pour agrandir l'image">
<a href="{{ $resolvedImage.RelPermalink }}" title="Cliquez pour agrandir l'image">
<img src="{{ $display.RelPermalink }}" alt="{{ $alt }}" title="{{ $title }}" />
</a>
{{- if $data.prompt }}
@@ -39,3 +58,4 @@
{{- end }}
{{- end }}
</figure>
{{- end -}}