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

82 lines
3.1 KiB
HTML

{{- $w := .Params.weather -}}
{{- if or (not $w) (eq (len $w) 0) -}}
{{- return -}}
{{- end -}}
{{- $date := .Date -}}
{{- $hour := (time $date).Hour -}}
{{- $isNight := false -}}
{{- if or (lt $hour 6) (ge $hour 18) -}}
{{- $isNight = true -}}
{{- end -}}
{{- $precip := $w.precipitations -}}
{{- $wind := $w.wind_speed -}}
{{- $humidity := $w.humidity -}}
{{- $illum := $w.illuminance -}}
{{- $icon := "clear-day.svg" -}}
{{- if $isNight -}}
{{- $icon = "clear-night.svg" -}}
{{- end -}}
{{- if $precip -}}
{{- $icon = "rain.svg" -}}
{{- else if and $wind (ge $wind 45) -}}
{{- $icon = "wind.svg" -}}
{{- else if and $humidity (ge $humidity 90) (or (not $illum) (lt $illum 80)) -}}
{{- $icon = "fog.svg" -}}
{{- else if and $humidity (ge $humidity 75) -}}
{{- if $isNight -}}
{{- $icon = "partly-cloudy-night.svg" -}}
{{- else -}}
{{- $icon = "cloudy.svg" -}}
{{- end -}}
{{- end -}}
{{- $label := "Météo" -}}
{{- if eq $icon "clear-day.svg" -}}{{- $label = "Grand soleil" -}}{{- end -}}
{{- if eq $icon "clear-night.svg" -}}{{- $label = "Ciel dégagé" -}}{{- end -}}
{{- if eq $icon "partly-cloudy-day.svg" -}}{{- $label = "Partiellement nuageux" -}}{{- end -}}
{{- if eq $icon "partly-cloudy-night.svg" -}}{{- $label = "Partiellement nuageux" -}}{{- end -}}
{{- if eq $icon "cloudy.svg" -}}{{- $label = "Nuageux" -}}{{- end -}}
{{- if eq $icon "drizzle.svg" -}}{{- $label = "Bruine" -}}{{- end -}}
{{- if eq $icon "rain.svg" -}}{{- $label = "Pluvieux" -}}{{- end -}}
{{- if eq $icon "snow.svg" -}}{{- $label = "Neige" -}}{{- end -}}
{{- if eq $icon "thunderstorms-day.svg" -}}{{- $label = "Orage" -}}{{- end -}}
{{- if eq $icon "fog.svg" -}}{{- $label = "Brouillard" -}}{{- end -}}
{{- if eq $icon "wind.svg" -}}{{- $label = "Vent fort" -}}{{- end -}}
{{- $sources := slice -}}
{{- with $w.source -}}
{{- if reflect.IsSlice . -}}
{{- $sources = . -}}
{{- else -}}
{{- $sources = slice . -}}
{{- end -}}
{{- end -}}
<section>
<h2>Météo observée</h2>
<p>
<img src="/icons/weather/{{ $icon }}" alt="{{ $label }}" title="{{ $label }}" loading="lazy">
<strong>{{ printf "%s à %s" (time.Format "02/01/2006" $date) (time.Format ":time_short" $date) }}</strong>
</p>
<dl>
{{- with $w.temperature -}}<div><dt>Température</dt><dd>{{ printf "%.1f" (mul . 1.0) }} °C</dd></div>{{- end -}}
{{- with $w.humidity -}}<div><dt>Humidité</dt><dd>{{ printf "%.0f" (mul . 1.0) }} %</dd></div>{{- end -}}
{{- with $w.pressure -}}<div><dt>Pression</dt><dd>{{ printf "%.0f" (mul . 1.0) }} hPa</dd></div>{{- end -}}
{{- with $w.illuminance -}}<div><dt>Luminosité</dt><dd>{{ printf "%.0f" (mul . 1.0) }} lx</dd></div>{{- end -}}
{{- with $w.wind_speed -}}<div><dt>Vent</dt><dd>{{ printf "%.1f" (mul . 1.0) }} km/h</dd></div>{{- end -}}
{{- with $w.wind_direction -}}<div><dt>Direction</dt><dd>{{ printf "%.0f" (mul . 1.0) }}°</dd></div>{{- end -}}
</dl>
{{- if gt (len $sources) 0 -}}
<p>
Sources:
{{- range $i, $source := $sources -}}
{{- if gt $i 0 -}}, {{- end -}}{{ $source }}
{{- end -}}
</p>
{{- end -}}
</section>