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

@@ -2,18 +2,39 @@
{{- $isCoverImage := false -}}
{{- $alt := "" -}}
{{- with .Params.cover -}}
{{- $cover := $.Resources.GetMatch . -}}
{{- $cover := false -}}
{{- $coverPath := (urls.Parse .).Path -}}
{{- if ne $coverPath "" -}}
{{- $coverPathLower := lower $coverPath -}}
{{- if or (strings.HasSuffix $coverPathLower ".yaml") (strings.HasSuffix $coverPathLower ".yml") -}}
{{- $coverDataFile := $.Resources.Get $coverPath -}}
{{- if $coverDataFile -}}
{{- with $coverDataFile.Content | transform.Unmarshal -}}
{{- with index . "file" -}}
{{- $coverFilePath := strings.TrimSpace (printf "%v" .) -}}
{{- if ne $coverFilePath "" -}}
{{- $cover = $.Resources.Get $coverFilePath -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- $cover = $.Resources.Get $coverPath -}}
{{- end -}}
{{- end -}}
{{- if and $cover (ne $cover.MediaType.SubType "svg") -}}
{{- $image = $cover -}}
{{- $isCoverImage = true -}}
{{- $coverName := path.Base . | replaceRE "\\.[^.]+$" "" -}}
{{- $coverDataFile := $.Resources.Get (printf "data/images/%s.yaml" $coverName) -}}
{{- if not $coverDataFile -}}
{{- $coverDataFile = $.Resources.Get (printf "data/%s.yaml" $coverName) -}}
{{- $coverDataFile = $.Resources.Get (printf "data/%s.yaml" $coverName) -}}
{{- end -}}
{{- $coverData := dict -}}
{{- if $coverDataFile -}}
{{- $coverData = $coverDataFile.Content | transform.Unmarshal -}}
{{- with $coverDataFile.Content | transform.Unmarshal -}}
{{- $coverData = . -}}
{{- end -}}
{{- end -}}
{{- $alt = index $coverData "description" | default "" -}}
{{- if not $alt -}}