1
Files
2025/themes/2026/layouts/_partials/page-links.html
2026-02-21 01:50:39 +01:00

97 lines
2.6 KiB
HTML

{{- $page := . -}}
{{- $commentsURL := "" -}}
{{- $commentsLabel := "Commentaires" -}}
{{- $linkClass := "" -}}
{{- $linksParam := $page.Params.links -}}
{{- if reflect.IsMap . -}}
{{- if isset . "Page" -}}
{{- $page = index . "Page" -}}
{{- end -}}
{{- if isset . "CommentsURL" -}}
{{- with (index . "CommentsURL") -}}
{{- $commentsURL = . -}}
{{- end -}}
{{- end -}}
{{- if isset . "CommentsLabel" -}}
{{- with (index . "CommentsLabel") -}}
{{- $commentsLabel = . -}}
{{- end -}}
{{- end -}}
{{- if isset . "LinkClass" -}}
{{- with (index . "LinkClass") -}}
{{- $linkClass = . -}}
{{- end -}}
{{- end -}}
{{- if isset . "Links" -}}
{{- $linksParam = index . "Links" -}}
{{- end -}}
{{- end -}}
{{- $links := slice -}}
{{- if $linksParam -}}
{{- $type := printf "%T" $linksParam -}}
{{- if hasPrefix $type "[]" -}}
{{- $links = $linksParam -}}
{{- else -}}
{{- $links = slice $linksParam -}}
{{- end -}}
{{- end -}}
{{- $hasWikipediaLink := false -}}
{{- range $links -}}
{{- if and (not $hasWikipediaLink) (and .url (in .url "wikipedia.org")) -}}
{{- $hasWikipediaLink = true -}}
{{- end -}}
{{- end -}}
{{- $addWikiLink := false -}}
{{- if and (eq $page.Kind "term") (not $hasWikipediaLink) -}}
{{- $addWikiLink = true -}}
{{- end -}}
{{- if or (ne $commentsURL "") (gt (len $links) 0) $addWikiLink -}}
<nav class="page-links" aria-label="Liens associés">
<ul>
{{- with $commentsURL -}}
<li>
{{- partial "render/link.html" (dict
"Destination" .
"Title" "Voir les commentaires"
"Text" $commentsLabel
"Class" $linkClass
"Page" $page
) -}}
</li>
{{- end -}}
{{- range $links -}}
{{- $text := default .name .text -}}
{{- $title := default $text .title -}}
<li>
{{- partial "render/link.html" (dict
"Destination" .url
"Title" $title
"Text" $text
"Class" $linkClass
"Page" $page
) -}}
</li>
{{- end -}}
{{- if $addWikiLink -}}
{{- $lang := default "fr" $page.Site.Language.Lang -}}
{{- $query := urlquery $page.Title -}}
{{- $searchUrl := printf "https://%s.wikipedia.org/w/index.php?search=%s" $lang $query -}}
<li>
{{- partial "render/link.html" (dict
"Destination" $searchUrl
"Title" (printf "Rechercher %s sur Wikipédia" $page.Title)
"Text" (printf "Rechercher %s sur Wikipédia" $page.Title)
"Class" $linkClass
"Page" $page
) -}}
</li>
{{- end -}}
</ul>
</nav>
{{- end -}}