1
Files
2025/themes/2026/layouts/_partials/article-header.html

297 lines
12 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{{- $page := . -}}
{{- $title := .Title -}}
{{- $showMeta := true -}}
{{- if reflect.IsMap . -}}
{{- with index . "Page" -}}
{{- $page = . -}}
{{- end -}}
{{- with index . "Title" -}}
{{- $title = . -}}
{{- end -}}
{{- if isset . "ShowMeta" -}}
{{- $showMeta = index . "ShowMeta" -}}
{{- end -}}
{{- end -}}
{{- $coverPath := $page.Params.cover -}}
{{- $isInterestingLink := strings.HasPrefix $page.RelPermalink "/interets/liens-interessants/" -}}
{{- $showCover := and $coverPath (not $isInterestingLink) -}}
{{- $linksParam := $page.Params.links -}}
{{- $links := slice -}}
{{- if $linksParam -}}
{{- $type := printf "%T" $linksParam -}}
{{- if hasPrefix $type "[]" -}}
{{- $links = $linksParam -}}
{{- else -}}
{{- $links = slice $linksParam -}}
{{- end -}}
{{- end -}}
{{- $originLink := dict -}}
{{- if $isInterestingLink -}}
{{- range $links -}}
{{- if and (eq (len $originLink) 0) .url -}}
{{- $rawLabel := default "" (default .name .text) -}}
{{- $normalizedLabel := lower (replace (replace (printf "%v" $rawLabel) "'" "") "" "") -}}
{{- if eq $normalizedLabel "page dorigine" -}}
{{- $originLink = . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if and (eq (len $originLink) 0) (gt (len $links) 0) -}}
{{- range $links -}}
{{- if and (eq (len $originLink) 0) .url -}}
{{- $originLink = . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $originURL := "" -}}
{{- $originLabel := "Page d'origine" -}}
{{- if gt (len $originLink) 0 -}}
{{- $originURL = default "" (index $originLink "url") -}}
{{- with (default (index $originLink "name") (index $originLink "text")) -}}
{{- $originLabel = . -}}
{{- end -}}
{{- end -}}
{{- $originIsExternal := strings.HasPrefix $originURL "http" -}}
{{- $remainingLinks := $links -}}
{{- if and $isInterestingLink (ne $originURL "") -}}
{{- $remainingLinks = slice -}}
{{- range $links -}}
{{- if and .url (ne .url $originURL) -}}
{{- $remainingLinks = $remainingLinks | append . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $coverData := dict -}}
{{- if $coverPath -}}
{{- $coverName := path.Base $coverPath | replaceRE "\\.[^.]+$" "" -}}
{{- $coverDataFile := $page.Resources.Get (printf "data/images/%s.yaml" $coverName) -}}
{{- if not $coverDataFile -}}
{{- $coverDataFile = $page.Resources.Get (printf "data/%s.yaml" $coverName) -}}
{{- end -}}
{{- if $coverDataFile -}}
{{- with $coverDataFile.Content | transform.Unmarshal -}}
{{- $coverData = . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $coverImage := false -}}
{{- $coverDisplay := false -}}
{{- if $showCover -}}
{{- $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" -}}
{{- $coverWidth := $coverDisplay.Width -}}
{{- if gt $coverDisplay.Width 1480 -}}
{{- $coverWidth = 1480 -}}
{{- end -}}
{{- $coverDisplay = partial "media/process-image.html" (dict
"image" $coverImage
"action" "Resize"
"spec" (printf "%dx" $coverWidth)
) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $coverImageTitle := default $title (index $coverData "title") -}}
{{- $coverTitle := index $coverData "title" -}}
{{- $coverDescription := index $coverData "description" -}}
{{- $coverAttribution := index $coverData "attribution" -}}
{{- $coverPrompt := index $coverData "prompt" -}}
{{- $weather := $page.Params.weather -}}
{{- $weatherIcon := "" -}}
{{- $weatherLabel := "Météo" -}}
{{- $weatherTitle := "" -}}
{{- if and $weather (gt (len $weather) 0) -}}
{{- $hour := (time $page.Date).Hour -}}
{{- $isNight := false -}}
{{- if or (lt $hour 6) (ge $hour 18) -}}
{{- $isNight = true -}}
{{- end -}}
{{- if $isNight -}}
{{- $weatherIcon = "clear-night.svg" -}}
{{- else -}}
{{- $weatherIcon = "clear-day.svg" -}}
{{- end -}}
{{- if $weather.precipitations -}}
{{- $weatherIcon = "rain.svg" -}}
{{- else if and $weather.wind_speed (ge $weather.wind_speed 45) -}}
{{- $weatherIcon = "wind.svg" -}}
{{- else if and $weather.humidity (ge $weather.humidity 90) (or (not $weather.illuminance) (lt $weather.illuminance 80)) -}}
{{- $weatherIcon = "fog.svg" -}}
{{- else if and $weather.humidity (ge $weather.humidity 75) -}}
{{- if $isNight -}}
{{- $weatherIcon = "partly-cloudy-night.svg" -}}
{{- else -}}
{{- $weatherIcon = "cloudy.svg" -}}
{{- end -}}
{{- end -}}
{{- if eq $weatherIcon "clear-day.svg" -}}{{- $weatherLabel = "Grand soleil" -}}{{- end -}}
{{- if eq $weatherIcon "clear-night.svg" -}}{{- $weatherLabel = "Ciel dégagé" -}}{{- end -}}
{{- if eq $weatherIcon "partly-cloudy-day.svg" -}}{{- $weatherLabel = "Partiellement nuageux" -}}{{- end -}}
{{- if eq $weatherIcon "partly-cloudy-night.svg" -}}{{- $weatherLabel = "Partiellement nuageux" -}}{{- end -}}
{{- if eq $weatherIcon "cloudy.svg" -}}{{- $weatherLabel = "Nuageux" -}}{{- end -}}
{{- if eq $weatherIcon "drizzle.svg" -}}{{- $weatherLabel = "Bruine" -}}{{- end -}}
{{- if eq $weatherIcon "rain.svg" -}}{{- $weatherLabel = "Pluvieux" -}}{{- end -}}
{{- if eq $weatherIcon "snow.svg" -}}{{- $weatherLabel = "Neige" -}}{{- end -}}
{{- if eq $weatherIcon "thunderstorms-day.svg" -}}{{- $weatherLabel = "Orage" -}}{{- end -}}
{{- if eq $weatherIcon "fog.svg" -}}{{- $weatherLabel = "Brouillard" -}}{{- end -}}
{{- if eq $weatherIcon "wind.svg" -}}{{- $weatherLabel = "Vent fort" -}}{{- end -}}
{{- $weatherTitleParts := slice -}}
{{- with $weather.temperature -}}
{{- $weatherTitleParts = $weatherTitleParts | append (printf "%.1f℃" (mul . 1.0)) -}}
{{- end -}}
{{- with $weather.humidity -}}
{{- $weatherTitleParts = $weatherTitleParts | append (printf "%.0f%%" (mul . 1.0)) -}}
{{- end -}}
{{- $weatherTitle = delimit $weatherTitleParts " | " -}}
{{- end -}}
{{- $hasWeatherIcon := ne $weatherIcon "" -}}
{{- $weatherAriaLabel := $weatherLabel -}}
{{- if ne $weatherTitle "" -}}
{{- $weatherAriaLabel = printf "Météo : %s" $weatherTitle -}}
{{- end -}}
{{- $hasCoverImage := and $showCover $coverImage -}}
{{- $hasCoverMeta := or $coverTitle $coverDescription $coverAttribution $coverPrompt -}}
{{- $showReadingTime := ge $page.ReadingTime 5 -}}
{{- $hasPublication := or $showReadingTime $hasWeatherIcon -}}
{{- with $page.Date -}}
{{- $hasPublication = true -}}
{{- end -}}
{{- $breadcrumbsMarkup := partial "breadcrumbs.html" $page -}}
{{- $hasBreadcrumbs := ne (strings.TrimSpace $breadcrumbsMarkup) "" -}}
{{- $pageLinksMarkup := partial "page-links.html" (dict
"Page" $page
"LinkClass" "ui-button"
"Links" $remainingLinks
) -}}
{{- $hasPageLinks := ne (strings.TrimSpace $pageLinksMarkup) "" -}}
{{- $hasOriginCallout := and $isInterestingLink (ne $originURL "") -}}
{{- $hasMetaMain := or $hasBreadcrumbs $hasPublication $hasPageLinks $hasOriginCallout -}}
{{- $showCoverMeta := and (not $isInterestingLink) $coverPath $hasCoverMeta -}}
{{- $hasMetaBlock := and $showMeta (or $hasCoverImage $hasMetaMain $showCoverMeta) -}}
<header class="article-header{{ if $isInterestingLink }} article-header--interesting-link{{ end }}">
{{ partialCached "header-brand.html" $page.Site $page.Site.Title ($page.Site.Params.logo | default "logo-large.png") }}
<h1>{{ $title }}</h1>
{{- if $hasMetaBlock -}}
<section class="article-meta-block{{ if not $hasCoverImage }} article-meta-block--without-cover{{ end }}">
{{- if $hasCoverImage -}}
<figure class="article-cover">
<a href="{{ $coverImage.RelPermalink }}" title="Cliquez pour agrandir l'image d'en-tête">
<img src="{{ $coverDisplay.RelPermalink }}" alt="{{ $coverImageTitle }}" title="{{ $coverImageTitle }}">
</a>
</figure>
{{- end -}}
<section class="article-meta">
<section class="article-meta-main">
{{- if $hasBreadcrumbs -}}
{{- $breadcrumbsMarkup | safeHTML -}}
{{- end -}}
{{- if $hasPublication -}}
<p class="article-publication">
{{ with $page.Date }}
{{- $timePart := . | time.Format "15:04:05" -}}
<time datetime="{{ .Format "2006-01-02T15:04:05Z07:00" }}">
{{- if eq $timePart "00:00:00" -}}
{{ . | time.Format "02/01/2006" }}
{{- else -}}
{{ . | time.Format "02/01/2006 à 15:04" }}
{{- end -}}
</time>
{{- if $hasWeatherIcon -}}
<span class="article-weather" role="img" aria-label="{{ $weatherAriaLabel }}"{{ with $weatherTitle }} title="{{ . }}"{{ end }}>
<img src="/icons/weather/{{ $weatherIcon }}" alt="" aria-hidden="true">
</span>
{{- end -}}
{{- if $showReadingTime -}}
<span>·</span>
{{- end -}}
{{ end }}
{{- if $showReadingTime -}}
<span>{{ $page.ReadingTime }} min de lecture</span>
{{- end -}}
</p>
{{- end -}}
{{- if $hasOriginCallout -}}
<section class="article-origin-link" aria-label="Lien d'origine">
<p class="article-origin-link-kicker">À lire avant mon commentaire</p>
<p class="article-origin-link-hint">Ce billet n'est qu'une note de lecture. Lisez d'abord la source pour avoir le contexte complet.</p>
<p class="article-origin-link-button">
{{- $originLinkText := printf "<span class=\"article-origin-link-button-label\">%s</span><span class=\"article-origin-link-button-url\">%s</span>" $originLabel $originURL -}}
{{- partial "render/link.html" (dict
"Destination" $originURL
"Title" "Lire la page d'origine"
"Text" $originLinkText
"Class" "ui-button article-origin-link-button-link"
"Page" $page
) -}}
</p>
</section>
{{- end -}}
{{- if $hasPageLinks -}}
{{- $pageLinksMarkup | safeHTML -}}
{{- end -}}
</section>
{{- if $showCoverMeta -}}
<section class="cover-meta">
<h2>Image d'en-tête</h2>
{{- with $coverTitle -}}
<p class="cover-title">{{ . | markdownify }}</p>
{{- end -}}
{{- with $coverDescription -}}
<p class="cover-description">{{ . | markdownify }}</p>
{{- end -}}
{{- with $coverAttribution -}}
{{- $attribution := partial "media/parse-attribution.html" . -}}
<p class="cover-attribution"><strong>Attribution:</strong> <span>{{- if index $attribution "isURL" -}}{{ partial "render/link.html" (dict "Destination" (index $attribution "url") "Page" $page "Text" (index $attribution "label")) }}{{- else -}}{{ . | markdownify }}{{- end -}}</span></p>
{{- end -}}
{{- with $coverPrompt -}}
<details>
<summary>Prompt</summary>
<p>{{ . | markdownify }}</p>
</details>
{{- end -}}
</section>
{{- end -}}
</section>
</section>
{{- end -}}
</header>