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

@@ -44,15 +44,24 @@
{{- $coverPath := $page.Params.cover -}}
{{- $image := 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 -}}
{{- $image = $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 "" -}}
{{- $image = $page.Resources.Get $coverFilePath -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- $image = $page.Resources.Get $coverResourcePath -}}
{{- end -}}
{{- else -}}
{{- $image = $page.Resources.GetMatch $coverPath -}}
{{- end -}}
{{- end -}}