1
Files
2025/themes/42/layouts/_partials/render/weather.html

99 lines
3.3 KiB
HTML

{{- $w := .Params.weather -}}
{{- if or (not $w) (eq (len $w) 0) -}}
{{- /* No weather data */ -}}
{{- return -}}
{{- end -}}
{{- $date := .Date -}}
{{- $hour := (time $date).Hour -}}
{{- $isNight := or (lt $hour 6) (ge $hour 18) -}}
{{- $precip := $w.precipitations -}}
{{- $wind := $w.wind_speed -}}
{{- $humidity := $w.humidity -}}
{{- $illum := $w.illuminance -}}
{{- $icon := cond $isNight "clear-night.svg" "clear-day.svg" -}}
{{- $labels := dict
"clear-day.svg" "Grand soleil"
"clear-night.svg" "Ciel dégagé"
"partly-cloudy-day.svg" "Partiellement nuageux"
"partly-cloudy-night.svg" "Partiellement nuageux"
"cloudy.svg" "Nuageux"
"drizzle.svg" "Bruine"
"rain.svg" "Pluvieux"
"snow.svg" "Neige"
"thunderstorms-day.svg" "Orage"
"fog.svg" "Brouillard"
"wind.svg" "Vent fort"
}}
{{- 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) -}}
{{- $icon = cond $isNight "partly-cloudy-night.svg" "cloudy.svg" -}}
{{- else -}}
{{- $icon = cond $isNight "clear-night.svg" "clear-day.svg" -}}
{{- end -}}
{{- $sources := slice -}}
{{- with $w.source -}}
{{- if (reflect.IsSlice .) -}}
{{- $sources = . -}}
{{- else -}}
{{- $sources = (slice .) -}}
{{- end -}}
{{- end -}}
<div class="panel weather">
<div class="weather-top">
{{- $label := index $labels $icon | default "Météo" -}}
<img class="weather-icon" src="/icons/weather/{{ $icon }}" alt="{{ $label }}" title="{{ $label }}" loading="lazy" />
<div class="weather-summary">
<div class="weather-line">
<span class="weather-date">{{ printf "%s — %s" (time.Format ":date_long" $date) (time.Format ":time_short" $date) }}</span>
</div>
<div class="weather-values">
{{- with $w.temperature }}
<span class="weather-value">{{ printf "%.1f" (mul . 1.0) }} °C</span>
{{- end }}
{{- with $w.humidity }}
<span class="weather-value">{{ printf "%.0f" (mul . 1.0) }} %</span>
{{- end }}
{{- with $w.pressure }}
<span class="weather-value">{{ printf "%.0f" (mul . 1.0) }} hPa</span>
{{- end }}
{{- with $w.illuminance }}
<span class="weather-value">{{ printf "%.0f" (mul . 1.0) }} lx</span>
{{- end }}
{{- if or $w.wind_speed $w.wind_direction }}
<span class="weather-value weather-wind">
{{- if $w.wind_direction -}}
{{- $rawDeg := mul $w.wind_direction 1.0 -}}
{{- $arrowDeg := math.Mod (add $rawDeg 180) 360 -}}
<svg class="weather-wind-arrow" viewBox="0 0 24 24" aria-hidden="true" style="transform: rotate({{ printf "%.0f" $arrowDeg }}deg);" title="{{ printf "%.0f°" $rawDeg }}">
<path d="M12 3l-4 7h3v11h2V10h3z" />
</svg>
{{- end -}}
{{- if $w.wind_speed -}}
{{ printf "%.1f" (mul $w.wind_speed 1.0) }} km/h
{{- end -}}
</span>
{{- end }}
</div>
{{- if gt (len $sources) 0 }}
<div class="weather-sources">
{{- range $sources }}
<span class="weather-source">{{ . }}</span>
{{- end }}
</div>
{{- end }}
</div>
</div>
</div>