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

@@ -17,9 +17,10 @@
{{- if or (strings.HasSuffix $coverPathLower ".yaml") (strings.HasSuffix $coverPathLower ".yml") -}}
{{- $coverDataFile := $page.Resources.GetMatch $coverPath -}}
{{- if $coverDataFile -}}
{{- $coverData := $coverDataFile.Content | transform.Unmarshal -}}
{{- with index $coverData "file" -}}
{{- $coverImagePath = strings.TrimSpace (printf "%v" .) -}}
{{- with $coverDataFile.Content | transform.Unmarshal -}}
{{- with index . "file" -}}
{{- $coverImagePath = strings.TrimSpace (printf "%v" .) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}
@@ -28,7 +29,8 @@
{{- end -}}
{{- $coverImageName := "" -}}
{{- if ne $coverImagePath "" -}}
{{- $coverImageName = lower (path.Base $coverImagePath) -}}
{{- $coverImageName = lower (path.Base ((urls.Parse $coverImagePath).Path)) -}}
{{- $coverImageName = replace $coverImageName "%20" " " -}}
{{- end -}}
{{- $contentImageNames := slice -}}
@@ -37,9 +39,12 @@
{{- range $imageTags -}}
{{- $srcMatch := findRESubmatch `(?is)src=["']([^"']+)["']` . -}}
{{- if gt (len $srcMatch) 0 -}}
{{- $src := lower (index (index $srcMatch 0) 1) -}}
{{- $srcRaw := index (index $srcMatch 0) 1 -}}
{{- $srcPath := (urls.Parse $srcRaw).Path -}}
{{- $src := lower $srcPath -}}
{{- if or (in $src "/images/") (strings.HasPrefix $src "images/") (strings.HasPrefix $src "./images/") -}}
{{- $srcName := path.Base $src -}}
{{- $srcName := lower (path.Base $srcPath) -}}
{{- $srcName = replace $srcName "%20" " " -}}
{{- $srcName = replaceRE "\\?.*$" "" $srcName -}}
{{- $srcName = replaceRE "#.*$" "" $srcName -}}
{{- $srcName = replaceRE "_hu_[^.]*" "" $srcName -}}
@@ -95,7 +100,9 @@
{{- $dataFile = $page.Resources.Get (printf "data/%s.yaml" $imageStem) -}}
{{- end -}}
{{- if $dataFile -}}
{{- $data = $dataFile.Content | transform.Unmarshal -}}
{{- with $dataFile.Content | transform.Unmarshal -}}
{{- $data = . -}}
{{- end -}}
{{- end -}}
{{- $title := default (printf "Image complémentaire : %s" $imageName) (index $data "title") -}}
{{- $thumbnail := . -}}