Résout les images référencées par des métadonnées YAML
This commit is contained in:
@@ -2,7 +2,26 @@
|
||||
{{- $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 -}}
|
||||
@@ -13,7 +32,9 @@
|
||||
{{- 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 -}}
|
||||
|
||||
@@ -61,14 +61,34 @@
|
||||
{{- $coverDataFile = $page.Resources.Get (printf "data/%s.yaml" $coverName) -}}
|
||||
{{- end -}}
|
||||
{{- if $coverDataFile -}}
|
||||
{{- $coverData = $coverDataFile.Content | transform.Unmarshal -}}
|
||||
{{- with $coverDataFile.Content | transform.Unmarshal -}}
|
||||
{{- $coverData = . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $coverImage := false -}}
|
||||
{{- $coverDisplay := false -}}
|
||||
{{- if $showCover -}}
|
||||
{{- $coverImage = $page.Resources.GetMatch $coverPath -}}
|
||||
{{- $coverResourcePath := (urls.Parse $coverPath).Path -}}
|
||||
{{- if ne $coverResourcePath "" -}}
|
||||
{{- $coverPathLower := lower $coverResourcePath -}}
|
||||
{{- if or (strings.HasSuffix $coverPathLower ".yaml") (strings.HasSuffix $coverPathLower ".yml") -}}
|
||||
{{- $coverMetaFile := $page.Resources.Get $coverResourcePath -}}
|
||||
{{- if $coverMetaFile -}}
|
||||
{{- with $coverMetaFile.Content | transform.Unmarshal -}}
|
||||
{{- with index . "file" -}}
|
||||
{{- $coverFilePath := strings.TrimSpace (printf "%v" .) -}}
|
||||
{{- if ne $coverFilePath "" -}}
|
||||
{{- $coverImage = $page.Resources.Get $coverFilePath -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- $coverImage = $page.Resources.Get $coverResourcePath -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if $coverImage -}}
|
||||
{{- $coverDisplay = $coverImage -}}
|
||||
{{- if ne $coverDisplay.MediaType.SubType "svg" -}}
|
||||
|
||||
@@ -17,18 +17,20 @@
|
||||
{{- 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" -}}
|
||||
{{- with $coverDataFile.Content | transform.Unmarshal -}}
|
||||
{{- with index . "file" -}}
|
||||
{{- $coverImagePath = strings.TrimSpace (printf "%v" .) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- $coverImagePath = $coverPath -}}
|
||||
{{- end -}}
|
||||
{{- 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 := . -}}
|
||||
|
||||
@@ -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.GetMatch $coverPath -}}
|
||||
{{- $image = $page.Resources.Get $coverResourcePath -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
@@ -1,21 +1,38 @@
|
||||
{{- $imgPath := .Destination -}}
|
||||
{{- $imgPath := (urls.Parse .Destination).Path -}}
|
||||
{{- $imgName := path.Base $imgPath | replaceRE "\\.[^.]+$" "" -}}
|
||||
{{- $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 := $data.description | default "" -}}
|
||||
{{- $image := .Page.Resources.GetMatch $imgPath -}}
|
||||
{{- if not $image -}}
|
||||
{{- return -}}
|
||||
{{- $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 -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- $image = .Page.Resources.Get $imgPath -}}
|
||||
{{- end -}}
|
||||
{{- with $image -}}
|
||||
{{- $resolvedImage := . -}}
|
||||
{{- $metaTitle := index $data "title" -}}
|
||||
{{- $hasMeta := or $metaTitle (or $description (or $data.attribution $data.prompt)) -}}
|
||||
{{- $attributes := .Attributes | default dict -}}
|
||||
{{- $attributes := $.Attributes | default dict -}}
|
||||
{{- $imageClasses := "" -}}
|
||||
{{- with index $attributes "class" -}}
|
||||
{{- $imageClasses = lower (trim . " ") -}}
|
||||
@@ -51,9 +68,9 @@
|
||||
{{- $figureClasses = $figureClasses | append . -}}
|
||||
{{- end -}}
|
||||
<figure class="{{ delimit $figureClasses " " }}">
|
||||
<a href="{{ $image.RelPermalink }}" title="Cliquez pour agrandir l'image">
|
||||
<a href="{{ $resolvedImage.RelPermalink }}" title="Cliquez pour agrandir l'image">
|
||||
{{- partial "media/display-img.html" (dict
|
||||
"image" $image
|
||||
"image" $resolvedImage
|
||||
"showMeta" $showMeta
|
||||
"forceCentered" $forceCentered
|
||||
"alt" $alt
|
||||
@@ -86,3 +103,4 @@
|
||||
</figcaption>
|
||||
{{- end -}}
|
||||
</figure>
|
||||
{{- end -}}
|
||||
|
||||
@@ -10,15 +10,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.GetMatch $coverPath -}}
|
||||
{{- $image = $page.Resources.Get $coverResourcePath -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
@@ -308,7 +308,25 @@
|
||||
|
||||
{{- $image := false -}}
|
||||
{{- with $page.Params.cover -}}
|
||||
{{- $image = $page.Resources.GetMatch . -}}
|
||||
{{- $coverResourcePath := (urls.Parse .).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 -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
<article>
|
||||
@@ -399,7 +417,25 @@
|
||||
{{- $item := . -}}
|
||||
{{- $itemImage := false -}}
|
||||
{{- with $item.Params.cover -}}
|
||||
{{- $itemImage = $item.Resources.GetMatch . -}}
|
||||
{{- $coverResourcePath := (urls.Parse .).Path -}}
|
||||
{{- if ne $coverResourcePath "" -}}
|
||||
{{- $coverPathLower := lower $coverResourcePath -}}
|
||||
{{- if or (strings.HasSuffix $coverPathLower ".yaml") (strings.HasSuffix $coverPathLower ".yml") -}}
|
||||
{{- $coverDataFile := $item.Resources.Get $coverResourcePath -}}
|
||||
{{- if $coverDataFile -}}
|
||||
{{- with $coverDataFile.Content | transform.Unmarshal -}}
|
||||
{{- with index . "file" -}}
|
||||
{{- $coverFilePath := strings.TrimSpace (printf "%v" .) -}}
|
||||
{{- if ne $coverFilePath "" -}}
|
||||
{{- $itemImage = $item.Resources.Get $coverFilePath -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- $itemImage = $item.Resources.Get $coverResourcePath -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
<li>
|
||||
<a href="{{ $item.RelPermalink }}" title="{{ $item.Title }}">
|
||||
|
||||
@@ -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 -}}
|
||||
|
||||
@@ -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 -}}
|
||||
|
||||
Reference in New Issue
Block a user