1

Bloc "Pour aller plus loin"

This commit is contained in:
2026-04-05 00:14:23 +02:00
parent 7592c9cace
commit adcb370623
19 changed files with 204 additions and 168 deletions

View File

@@ -1,7 +1,8 @@
{{- $commentsMarkup := strings.TrimSpace (partial "asides/comments.html" .) -}}
{{- $keywordsMarkup := strings.TrimSpace (partial "asides/keywords.html" .) -}}
{{- $furtherReadingMarkup := strings.TrimSpace (partial "article-further-reading.html" .) -}}
{{- $relatedMarkup := strings.TrimSpace (partial "article-related.html" .) -}}
{{- if or (ne $commentsMarkup "") (ne $keywordsMarkup "") (ne $relatedMarkup "") -}}
{{- if or (ne $commentsMarkup "") (ne $keywordsMarkup "") (ne $furtherReadingMarkup "") (ne $relatedMarkup "") -}}
<section class="article-asides">
{{- with $commentsMarkup -}}
{{- . | safeHTML -}}
@@ -9,6 +10,9 @@
{{- with $keywordsMarkup -}}
{{- . | safeHTML -}}
{{- end -}}
{{- with $furtherReadingMarkup -}}
{{- . | safeHTML -}}
{{- end -}}
{{- with $relatedMarkup -}}
{{- . | safeHTML -}}
{{- end -}}

View File

@@ -0,0 +1,10 @@
{{- $items := partial "resolve-pages-from-urls.html" (dict
"URLs" .Params.further_reading
"CurrentPage" .
) -}}
{{- partial "article-pages-block.html" (dict
"Title" "Pour aller plus loin"
"Class" "article-further-reading"
"Pages" $items
"ShowDossierBeforeTitle" true
) -}}

View File

@@ -0,0 +1,27 @@
{{- $title := "" -}}
{{- $class := "" -}}
{{- $pages := slice -}}
{{- $showDossierBeforeTitle := false -}}
{{- if reflect.IsMap . -}}
{{- with .Title -}}
{{- $title = . -}}
{{- end -}}
{{- with .Class -}}
{{- $class = . -}}
{{- end -}}
{{- with .Pages -}}
{{- $pages = . -}}
{{- end -}}
{{- if isset . "ShowDossierBeforeTitle" -}}
{{- $showDossierBeforeTitle = index . "ShowDossierBeforeTitle" -}}
{{- end -}}
{{- end -}}
{{- if and (ne $title "") (gt (len $pages) 0) -}}
<section class="article-aside-block article-page-links{{ with $class }} {{ . }}{{ end }}">
<h2>{{ $title }}</h2>
{{- partial "articles-list.html" (dict
"Pages" $pages
"ShowDossierBeforeTitle" $showDossierBeforeTitle
) -}}
</section>
{{- end -}}

View File

@@ -39,13 +39,10 @@
{{- end -}}
{{- end -}}
{{- if gt (len $items) 0 -}}
<section class="article-aside-block article-related">
<h2>Articles relatifs</h2>
{{- partial "articles-list.html" (dict
"Pages" $items
"ShowDossierBeforeTitle" true
) -}}
</section>
{{- end -}}
{{- partial "article-pages-block.html" (dict
"Title" "Articles relatifs"
"Class" "article-related"
"Pages" $items
"ShowDossierBeforeTitle" true
) -}}
{{- end -}}

View File

@@ -0,0 +1,62 @@
{{- $rawURLs := slice -}}
{{- $currentPage := false -}}
{{- if reflect.IsMap . -}}
{{- with .URLs -}}
{{- $rawURLs = . -}}
{{- end -}}
{{- with .CurrentPage -}}
{{- $currentPage = . -}}
{{- end -}}
{{- else -}}
{{- $rawURLs = . -}}
{{- end -}}
{{- $urls := slice -}}
{{- if reflect.IsSlice $rawURLs -}}
{{- $urls = $rawURLs -}}
{{- else -}}
{{- $singleURL := strings.TrimSpace (printf "%v" $rawURLs) -}}
{{- if ne $singleURL "" -}}
{{- $urls = slice $singleURL -}}
{{- end -}}
{{- end -}}
{{- $pages := slice -}}
{{- $seen := dict -}}
{{- range $urls -}}
{{- $rawURL := strings.TrimSpace (printf "%v" .) -}}
{{- if ne $rawURL "" -}}
{{- $parsedURL := urls.Parse $rawURL -}}
{{- $path := strings.TrimSpace $parsedURL.Path -}}
{{- if eq $path "" -}}
{{- $path = $rawURL -}}
{{- end -}}
{{- if not (strings.HasPrefix $path "/") -}}
{{- $path = printf "/%s" $path -}}
{{- end -}}
{{- if not (strings.HasSuffix $path "/") -}}
{{- $path = printf "%s/" $path -}}
{{- end -}}
{{- $match := false -}}
{{- $matches := where site.RegularPages "RelPermalink" "eq" $path -}}
{{- if gt (len $matches) 0 -}}
{{- $match = index $matches 0 -}}
{{- else -}}
{{- $matches = where site.RegularPages "Aliases" "intersect" (slice $path) -}}
{{- if gt (len $matches) 0 -}}
{{- $match = index $matches 0 -}}
{{- end -}}
{{- end -}}
{{- if $match -}}
{{- $matchedPermalink := $match.RelPermalink -}}
{{- $isCurrentPage := and $currentPage (eq $matchedPermalink $currentPage.RelPermalink) -}}
{{- if and (not $isCurrentPage) (not (isset $seen $matchedPermalink)) -}}
{{- $pages = $pages | append $match -}}
{{- $seen = merge $seen (dict $matchedPermalink true) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- return $pages -}}