1

Affichage des images non intégrées

This commit is contained in:
2026-03-05 14:42:12 +01:00
parent 5b355aca6a
commit b180242590
4 changed files with 160 additions and 0 deletions

View File

@@ -858,6 +858,49 @@ aside section dl > div {
padding-top: var(--space-2); padding-top: var(--space-2);
} }
body:has(> header.article-header) > main > aside.article-complementary-images {
width: min(100%, var(--max-width-reading));
margin-inline: auto;
margin-top: var(--space-6);
}
body:has(> header.article-header) > main > aside.article-complementary-images > section {
margin-top: 0;
border-top: 1px solid var(--color-border);
padding-top: var(--space-3);
}
body:has(> header.article-header) > main > aside.article-complementary-images > section > h2 {
margin-top: 0;
font-size: 1.02rem;
text-transform: uppercase;
letter-spacing: 0.08em;
}
body:has(> header.article-header) > main > aside.article-complementary-images > section > ul {
list-style: none;
margin-top: var(--space-3);
padding-left: 0;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
gap: var(--space-3);
}
body:has(> header.article-header) > main > aside.article-complementary-images > section > ul > li {
margin-top: 0;
}
body:has(> header.article-header) > main > aside.article-complementary-images > section > ul > li > a {
display: block;
border: 1px solid var(--color-border);
}
body:has(> header.article-header) > main > aside.article-complementary-images > section > ul > li > a > img {
width: 100%;
height: auto;
display: block;
}
body:has(> header.article-header) > main > aside.article-toc { body:has(> header.article-header) > main > aside.article-toc {
position: fixed; position: fixed;
inset-inline-end: var(--space-2); inset-inline-end: var(--space-2);

View File

@@ -0,0 +1,115 @@
{{- $page := . -}}
{{- $bundleImages := slice -}}
{{- range $page.Resources.ByType "image" -}}
{{- if strings.HasPrefix .Name "images/" -}}
{{- $bundleImages = $bundleImages | append . -}}
{{- end -}}
{{- end -}}
{{- if gt (len $bundleImages) 0 -}}
{{- $coverPath := "" -}}
{{- with $page.Params.cover -}}
{{- $coverPath = strings.TrimSpace (printf "%v" .) -}}
{{- end -}}
{{- $coverImagePath := "" -}}
{{- if ne $coverPath "" -}}
{{- $coverPathLower := lower $coverPath -}}
{{- 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" .) -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- $coverImagePath = $coverPath -}}
{{- end -}}
{{- end -}}
{{- $coverImageName := "" -}}
{{- if ne $coverImagePath "" -}}
{{- $coverImageName = lower (path.Base $coverImagePath) -}}
{{- end -}}
{{- $contentImageNames := slice -}}
{{- $contentImageStems := slice -}}
{{- $imageTags := findRE `(?is)<img[^>]+src=["'][^"']+["'][^>]*>` .Content -}}
{{- range $imageTags -}}
{{- $srcMatch := findRESubmatch `(?is)src=["']([^"']+)["']` . -}}
{{- if gt (len $srcMatch) 0 -}}
{{- $src := lower (index (index $srcMatch 0) 1) -}}
{{- if or (in $src "/images/") (strings.HasPrefix $src "images/") (strings.HasPrefix $src "./images/") -}}
{{- $srcName := path.Base $src -}}
{{- $srcName = replaceRE "\\?.*$" "" $srcName -}}
{{- $srcName = replaceRE "#.*$" "" $srcName -}}
{{- $srcName = replaceRE "_hu_[^.]*" "" $srcName -}}
{{- $srcStem := $srcName | replaceRE "\\.[^.]+$" "" -}}
{{- $contentImageNames = $contentImageNames | append $srcName -}}
{{- $contentImageStems = $contentImageStems | append $srcStem -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $unusedImages := slice -}}
{{- range $bundleImages -}}
{{- $imageName := path.Base .Name -}}
{{- $imageNameLower := lower $imageName -}}
{{- $isCoverImage := false -}}
{{- if and (ne $coverImageName "") (eq $imageNameLower $coverImageName) -}}
{{- $isCoverImage = true -}}
{{- end -}}
{{- if not $isCoverImage -}}
{{- $imageStem := $imageName | replaceRE "\\.[^.]+$" "" -}}
{{- $imageStemLower := lower $imageStem -}}
{{- $isUsedInContent := false -}}
{{- range $contentImageNames -}}
{{- if eq . $imageNameLower -}}
{{- $isUsedInContent = true -}}
{{- end -}}
{{- end -}}
{{- if not $isUsedInContent -}}
{{- range $contentImageStems -}}
{{- if eq . $imageStemLower -}}
{{- $isUsedInContent = true -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if not $isUsedInContent -}}
{{- $unusedImages = $unusedImages | append . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if gt (len $unusedImages) 0 -}}
<aside class="article-complementary-images">
<section>
<h2>Images complémentaires</h2>
<ul>
{{- range $unusedImages -}}
{{- $imageName := path.Base .Name -}}
{{- $imageStem := $imageName | replaceRE "\\.[^.]+$" "" -}}
{{- $data := dict -}}
{{- $dataFile := $page.Resources.Get (printf "data/images/%s.yaml" $imageStem) -}}
{{- if not $dataFile -}}
{{- $dataFile = $page.Resources.Get (printf "data/%s.yaml" $imageStem) -}}
{{- end -}}
{{- if $dataFile -}}
{{- $data = $dataFile.Content | transform.Unmarshal -}}
{{- end -}}
{{- $title := default (printf "Image complémentaire : %s" $imageName) (index $data "title") -}}
{{- $thumbnail := . -}}
{{- if and (ne .MediaType.SubType "svg") (gt .Width 360) -}}
{{- $thumbnail = .Resize "360x" -}}
{{- end -}}
<li>
<a href="{{ .RelPermalink }}" title="{{ $title }}">
<img src="{{ $thumbnail.RelPermalink }}" alt="{{ $title }}" loading="lazy" decoding="async">
</a>
</li>
{{- end -}}
</ul>
</section>
</aside>
{{- end -}}
{{- end -}}

View File

@@ -6,6 +6,7 @@
{{ partial "liens-morts/report.html" (dict "Page" .) }} {{ partial "liens-morts/report.html" (dict "Page" .) }}
{{ partial "article-footer.html" . }} {{ partial "article-footer.html" . }}
</article> </article>
{{ partial "asides/complementary-images.html" . }}
{{ partial "asides/toc.html" . }} {{ partial "asides/toc.html" . }}
</main> </main>
{{ end }} {{ end }}

View File

@@ -5,6 +5,7 @@
{{ .Content }} {{ .Content }}
{{ partial "article-footer.html" . }} {{ partial "article-footer.html" . }}
</article> </article>
{{ partial "asides/complementary-images.html" . }}
{{ partial "asides/toc.html" . }} {{ partial "asides/toc.html" . }}
</main> </main>
{{ end }} {{ end }}