This commit is contained in:
2026-01-14 13:37:09 +01:00
parent af72413e7d
commit be3498f2da
+138 -144
View File
@@ -371,7 +371,7 @@ data:
body-type: string
cache: 1h
options:
location: Budapest, Hungary
location: Budapest VIII., Hungary
weekend_color: "#34363D"
color_clear: "#FFA500"
color_partly: "#EBE387"
@@ -383,22 +383,16 @@ data:
color_snow: "#FFFFFF"
color_thunderstorm: "#696969"
color_other: "#FFFFFF"
# Optional: set this to control the dark “tint” over the colored bars (numbers sit on top of this)
# overlay_color: "rgba(0,0,0,0.20)"
# Optional: override bar colors directly if you dont want to rely on Glance theme vars
# color_red: "#ff5a5f"
# color_yellow: "#ffd166"
# color_blue: "#06d6a0"
# color_white: "#ffffff"
template: |
{{ $loc := .Options.StringOr "location" "Budapest, Hungary" }}
{{ $weekend_color := .Options.StringOr "weekend_color" "#34363D" }}
{{ $overlay_color := .Options.StringOr "overlay_color" "hsl(var(--bghs), var(--bgl), 50%)" }}
color_red: "#F08C46"
color_yellow: "#F0F046"
color_blue: "#46F0F0"
color_white: "#FFFFFF"
overlay_color: "rgba(0,0,0,0.20)" #Was pink with "rgba(255,0,255,0.20)"
template: |
{{/* Weather widget fully customizable via options */}}
{{ $temp_unit := .Options.StringOr "temp_unit" "celsius" }}
{{ $weekend_color := .Options.StringOr "weekend_color" "var(--color-separator)" }}
{{ $overlay_color := .Options.StringOr "overlay_color" "rgba(0,0,0,0.35)" }}
{{ $color_clear := .Options.StringOr "color_clear" "var(--color-text-highlight)" }}
{{ $color_partly := .Options.StringOr "color_partly" "var(--color-text-highlight)"}}
{{ $color_cloud := .Options.StringOr "color_cloud" "var(--color-text-highlight)"}}
@@ -406,169 +400,170 @@ data:
{{ $color_drizzle := .Options.StringOr "color_drizzle" "var(--color-text-highlight)"}}
{{ $color_rain := .Options.StringOr "color_rain" "var(--color-text-highlight)"}}
{{ $color_freezing_rain := .Options.StringOr "color_freezing_rain" "var(--color-text-highlight)"}}
{{ $color_snow := .Options.StringOr "color_snow" "var(--color-text-highlight)"}}
{{ $color_snow := .Options.StringOr "color_snow" "var(--color-text-highlight)F"}}
{{ $color_thunderstorm := .Options.StringOr "color_thunderstorm" "var(--color-text-highlight)"}}
{{ $color_other := .Options.StringOr "color_other" "var(--color-text-highlight)"}}
{{ $color_red := .Options.StringOr "color_red" "var(--color-negative)" }}
{{ $color_red := .Options.StringOr "color_red" "var(--color-negative)" }}
{{ $color_yellow := .Options.StringOr "color_yellow" "var(--color-text-subdue)" }}
{{ $color_blue := .Options.StringOr "color_blue" "var(--color-positive)" }}
{{ $color_white := .Options.StringOr "color_white" "var(--color-text-highlight)" }}
{{/* Open-Meteo: geocoding */}}
{{ $geo := newRequest (printf "https://geocoding-api.open-meteo.com/v1/search?name=%s&count=1&language=en&format=json" ($loc | urlquery)) }}
{{ $geo = $geo.Do }}
{{ $lat := 47.4979 }}
{{ $lon := 19.0402 }}
{{ if gt ($geo.JSON.Array "results" | len) 0 }}
{{ $lat = (index ($geo.JSON.Array "results") 0).Float "latitude" }}
{{ $lon = (index ($geo.JSON.Array "results") 0).Float "longitude" }}
{{ end }}
{{/* Open-Meteo: daily forecast */}}
{{ $req2 := newRequest (printf "https://api.open-meteo.com/v1/forecast?latitude=%f&longitude=%f&daily=weathercode,temperature_2m_max,temperature_2m_min&timezone=auto" $lat $lon) }}
{{ $req2 = $req2.Do }}
{{ $dates := $req2.JSON.Array "daily.time" }}
{{ $codes := $req2.JSON.Array "daily.weathercode" }}
{{ $maxTemps := $req2.JSON.Array "daily.temperature_2m_max" }}
{{ $minTemps := $req2.JSON.Array "daily.temperature_2m_min" }}
{{/* Title */}}
<div style="display:flex; align-items:center; justify-content:space-between;">
<div style="font-weight:600; letter-spacing:0.5px;">WEATHER&nbsp;&nbsp;FORECAST</div>
</div>
<div style="height:1px; width:100%; background:rgba(255,255,255,0.15); margin:8px 0 10px 0;"></div>
{{/* Day headers + icons */}}
<div style="display:flex; justify-content:space-between; gap:6px; padding:0 2px;">
{{ range $i, $d := $dates }}
{{ if lt $i 7 }}
{{ $day := (toDate "2006-01-02" ($d.String "")).Format "Mon" }}
{{ $isWeekend := or (eq $day "Sat") (eq $day "Sun") }}
<div style="width:14%; text-align:center;">
<div style="font-size:13px; color:rgba(255,255,255,0.85); margin-bottom:4px;">{{ $day }}</div>
{{ if $isWeekend }}
<div style="display:inline-block; padding:6px 10px; border-radius:3px; background:{{ $weekend_color | safeCSS }}; margin-bottom:6px; font-size:13px;">
{{ (toDate "2006-01-02" ($d.String "")).Format "02" }}
</div>
{{ else }}
<div style="display:inline-block; padding:6px 10px; border-radius:3px; background:transparent; margin-bottom:6px; font-size:13px;">
{{ (toDate "2006-01-02" ($d.String "")).Format "02" }}
</div>
{{ end }}
{{ $code := (index $codes $i).Int "" }}
{{ $wtype := "Other" }}
{{ $wicon := "fas fa-question" }}
{{ $wcolor := $color_other }}
{{/* NOTE: if you ever hit "function has not defined" again, convert these 'has' blocks to explicit ORs */}}
{{ if or (eq $code 0) (eq $code 1) }}
{{ $wtype = "Clear" }}
{{ $wicon = "fas fa-sun" }}
{{ $wcolor = $color_clear }}
{{ else if or (eq $code 2) (eq $code 3) }}
{{ $wtype = "Partly cloudy" }}
{{ $wicon = "fas fa-cloud-sun" }}
{{ $wcolor = $color_partly }}
{{ else if or (eq $code 45) (eq $code 48) }}
{{ $wtype = "Fog" }}
{{ $wicon = "fas fa-smog" }}
{{ $wcolor = $color_smog }}
{{ else if or (eq $code 51) (eq $code 53) (eq $code 55) (eq $code 56) (eq $code 57) }}
{{ $wtype = "Drizzle" }}
{{ $wicon = "fas fa-cloud-rain" }}
{{ $wcolor = $color_drizzle }}
{{ else if or (eq $code 61) (eq $code 63) (eq $code 65) (eq $code 80) (eq $code 81) (eq $code 82) }}
{{ $wtype = "Rain" }}
{{ $wicon = "fas fa-cloud-showers-heavy" }}
{{ $wcolor = $color_rain }}
{{ else if or (eq $code 66) (eq $code 67) }}
{{ $wtype = "Freezing Rain" }}
{{ $wicon = "fas fa-snowflake" }}
{{ $wcolor = $color_freezing_rain }}
{{ else if or (eq $code 71) (eq $code 73) (eq $code 75) (eq $code 77) (eq $code 85) (eq $code 86) }}
{{ $wtype = "Snow" }}
{{ $wicon = "fas fa-snowflake" }}
{{ $wcolor = $color_snow }}
{{ else if or (eq $code 95) (eq $code 96) (eq $code 99) }}
{{ $wtype = "Thunderstorm" }}
{{ $wicon = "fas fa-bolt" }}
{{ $wcolor = $color_thunderstorm }}
{{ else if or (eq $code 4) (eq $code 5) (eq $code 6) (eq $code 7) (eq $code 8) }}
{{ $wtype = "Cloudy" }}
{{ $wicon = "fas fa-cloud" }}
{{ $wcolor = $color_cloud }}
{{ end }}
<div>
<i class={{ $wicon }} style="font-size: 20px; color: {{ $wcolor | safeCSS }};" title={{ $wtype }}></i>
</div>
{{ $temp_red := .Options.FloatOr "temp_red" 27 }}
{{ $temp_yellow := .Options.FloatOr "temp_yellow" 20 }}
{{ $temp_blue := .Options.FloatOr "temp_blue" 10.0 }}
{{ $temp_white := .Options.FloatOr "temp_white" 0 }}
{{ if eq $temp_unit "fahrenheit" }}
{{ $temp_red = .Options.FloatOr "temp_red" 80.0 }}
{{ $temp_yellow = .Options.FloatOr "temp_yellow" 70.0 }}
{{ $temp_blue = .Options.FloatOr "temp_blue" 50.0 }}
{{ $temp_white = .Options.FloatOr "temp_white" 30.0 }}
{{end}}
{{ $location_string := replaceAll " " "%20" (.Options.StringOr "location" "") }}
{{ $url1 := printf "https://geocoding-api.open-meteo.com/v1/search?name=%s&count=20&language=en&format=json" $location_string }}
{{ $req1 := newRequest $url1 | getResponse }}
{{ $latitude := $req1.JSON.String "results.0.latitude" }}
{{ $longitude := $req1.JSON.String "results.0.longitude" }}
{{ $url2 := printf "https://api.open-meteo.com/v1/forecast?latitude=%s&longitude=%s&temperature_unit=%s&daily=temperature_2m_max,temperature_2m_min,weathercode&timezone=Europe/Budapest" $latitude $longitude $temp_unit}}
{{ $req2 := newRequest $url2 | getResponse }}
<div style="display: flex; justify-content: center; align-items: center; flex-direction: column;">
{{ $dates := $req2.JSON.Array "daily.time" }}
<div style="position: relative; width: 100%; height: 25px;">
{{ range $index, $date := $dates }}
{{ $dateString := .String "" }}
{{ $parsedDate := $dateString | parseTime "DateOnly" }}
{{ $dayOfWeek := $parsedDate.Format "Monday" | trimSuffix "day" | trimSuffix "on" | trimSuffix "es" | trimSuffix "edn" | trimSuffix "urs" | trimSuffix "ri" | trimSuffix "tur" | trimSuffix "n" }}
{{ $day_color := "" }}
{{ if eq $dayOfWeek "Sa" "Su" }}
{{ $day_color = $weekend_color }}
{{ end }}
<div style="text-align: center; width: 10%; height: 25px; line-height: 25px; margin: 0 10% 0 3%; left: {{ mul $index 14 }}%; position: absolute; background-color: {{ $day_color | safeCSS }} ">
<p class="size-h4 color-paragraph">{{ $dayOfWeek }}</p>
</div>
{{ end }}
{{ end }}
</div>
<div style="position: relative; width: 100%; height: 25px;">
{{ range $index, $date := $dates }}
{{ $dateString := .String "" }}
{{ $trimmedDate := replaceMatches "[0-9]+-[0-9]+-" "" $dateString }}
<div style="text-align: center; width: 10%; height: 25px; line-height: 25px; margin: 0 10% 0 3%; left: {{ mul $index 14 }}%; position: absolute;">
<p class="size-h4 color-paragraph">{{ $trimmedDate }}</p>
</div>
{{ end }}
</div>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
{{ $codes := $req2.JSON.Array "daily.weathercode" }}
<div style="position: relative; width: 100%; height: 30px;">
{{ range $index, $thiscode := $codes }}
{{ $code := .Int "" }}
<div style="text-align: center; width: 10%; height: 25px; line-height: 25px; margin: 0 10% 0 3%; left: {{ mul $index 14 }}% ; position: absolute;">
{{ $wtype := "" }}
{{ $wicon := "" }}
{{ $wcolor := "" }}
{{ if eq $code 0 }}
{{ $wtype = "Clear" }}
{{ $wicon = "fas fa-sun" }}
{{ $wcolor = $color_clear }}
{{ else if or (eq $code 1) (eq $code 2) }}
{{ $wtype = "Part Clear" }}
{{ $wicon = "fas fa-cloud-sun" }}
{{ $wcolor = $color_partly }}
{{ else if eq $code 3 }}
{{ $wtype = "Cloudy" }}
{{ $wicon = "fas fa-cloud" }}
{{ $wcolor = $color_cloud }}
{{ else if or (eq $code 45) (eq $code 48) }}
{{ $wtype = "Fog" }}
{{ $wicon = "fas fa-smog" }}
{{ $wcolor = $color_smog }}
{{/* Drizzle */}}
{{ else if or (eq $code 51) (eq $code 53) (eq $code 55) (eq $code 56) (eq $code 57) }}
{{ $wtype = "Drizzle" }}
{{ $wicon = "fas fa-cloud-rain" }}
{{ $wcolor = $color_drizzle }}
{{/* Rain */}}
{{ else if or (eq $code 61) (eq $code 63) (eq $code 65) (eq $code 80) (eq $code 81) (eq $code 82) }}
{{ $wtype = "Rain" }}
{{ $wicon = "fas fa-cloud-showers-heavy" }}
{{ $wcolor = $color_rain }}
{{ else if or (eq $code 66) (eq $code 67) }}
{{ $wtype = "Freezing Rain" }}
{{ $wicon = "fas fa-snowflake" }}
{{ $wcolor = $color_freezing_rain }}
{{/* Snow */}}
{{ else if or (eq $code 71) (eq $code 73) (eq $code 75) (eq $code 77) (eq $code 85) (eq $code 86) }}
{{ $wtype = "Snow" }}
{{ $wicon = "fas fa-snowman" }}
{{ $wcolor = $color_snow }}
{{/* Thunderstorm */}}
{{ else if or (eq $code 95) (eq $code 96) (eq $code 99) }}
{{ $wtype = "Thunderstorm" }}
{{ $wicon = "fas fa-bolt" }}
{{ $wcolor = $color_thunderstorm }}
{{ else }}
{{ $wtype = "Other" }}
{{ $wicon = "fa-solid fa-question" }}
{{ $wcolor = $color_other }}
{{ end }}
<i class={{ $wicon }} style="font-size: 20px; color: {{ $wcolor | safeCSS }};" title={{ $wtype }}></i>
</div>
{{ end }}
</div>
</div>
{{/* Temperature bars */}}
<div style="display:flex; justify-content:flex-start; align-items:center; margin-top:10px;">
{{ $maxTemps := $req2.JSON.Array "daily.temperature_2m_max" }}
{{ $minTemps := $req2.JSON.Array "daily.temperature_2m_min" }}
<div style="display: flex; justify-content: flex-start; align-items: center;">
{{ $max_max := 0 }}
{{ range $maxTemps }}{{ if gt (.Int "") $max_max }}{{ $max_max = (.Int "") }}{{ end }}{{ end }}
{{ range $maxTemps }}
{{ if gt (.Int "") $max_max }}
{{ $max_max = (.Int "") }}
{{ end }}
{{ end }}
{{ $min_min := 999 }}
{{ range $minTemps }}{{ if lt (.Int "") $min_min }}{{ $min_min = (.Int "") }}{{ end }}{{ end }}
{{ range $minTemps }}
{{ if lt (.Int "") $min_min }}
{{ $min_min = (.Int "") }}
{{ end }}
{{ end }}
{{ $max_max = add $max_max 1 }}
{{ $min_min = sub $min_min 1 }}
<div style="position: relative; width: 100%; height: 75px;">
{{ $temp_range := sub $max_max $min_min }}
{{/* thresholds for the 4 bands */}}
{{ $temp_red := add $min_min (mul 0.25 $temp_range) }}
{{ $temp_yellow := add $min_min (mul 0.50 $temp_range) }}
{{ $temp_blue := add $min_min (mul 0.75 $temp_range) }}
{{ $temp_white := $max_max }}
{{ range $index, $thisHigh := $maxTemps }}
{{ if lt $index 7 }}
{{ $thisLow := index $minTemps $index }}
{{ $thisHigh = $thisHigh.Float "" }}
{{ $thisLow = $thisLow.Float "" }}
{{ $thisHighPct := sub 1 (div (sub $max_max $thisHigh) $temp_range) }}
{{ $thisLowPct := div (sub $thisLow $min_min) $temp_range }}
{{ $thisTempRange := sub $thisHigh $thisLow }}
{{ if eq $thisTempRange 0 }}{{ $thisTempRange = 1 }}{{ end }}
{{/* Guard against division-by-zero if highs == lows */}}
{{ if eq $thisTempRange 0.0 }}
{{ $thisTempRange = 0.0001 }}
{{ end }}
{{ $red_pos := mul 100 (div (sub $thisHigh $temp_red) $thisTempRange) | toInt }}
{{ $yel_pos := mul 100 (div (sub $thisHigh $temp_yellow) $thisTempRange) | toInt }}
{{ $blu_pos := mul 100 (div (sub $thisHigh $temp_blue) $thisTempRange) | toInt }}
{{ $whi_pos := mul 100 (div (sub $thisHigh $temp_white) $thisTempRange) | toInt }}
{{/* Clamp stops into 0..100 */}}
{{/* Clamp to 0..100 */}}
{{ $pRed := $red_pos }}{{ if lt $pRed 0 }}{{ $pRed = 0 }}{{ end }}{{ if gt $pRed 100 }}{{ $pRed = 100 }}{{ end }}
{{ $pYel := $yel_pos }}{{ if lt $pYel 0 }}{{ $pYel = 0 }}{{ end }}{{ if gt $pYel 100 }}{{ $pYel = 100 }}{{ end }}
{{ $pBlu := $blu_pos }}{{ if lt $pBlu 0 }}{{ $pBlu = 0 }}{{ end }}{{ if gt $pBlu 100 }}{{ $pBlu = 100 }}{{ end }}
{{ $pWhi := $whi_pos }}{{ if lt $pWhi 0 }}{{ $pWhi = 0 }}{{ end }}{{ if gt $pWhi 100 }}{{ $pWhi = 100 }}{{ end }}
{{/* Ensure non-decreasing stops */}}
{{ if lt $pYel $pRed }}{{ $pYel = $pRed }}{{ end }}
{{ if lt $pBlu $pYel }}{{ $pBlu = $pYel }}{{ end }}
{{ if lt $pWhi $pBlu }}{{ $pWhi = $pBlu }}{{ end }}
<div style="left: {{ mul $index 14 | add 3 }}%; bottom: {{ mul $thisLowPct 100 | toInt }}%;
height: {{ mul (sub $thisHighPct $thisLowPct) 100 | toInt }}%; position: absolute;
width: 10%; text-align: center; border-radius: 10px; overflow: hidden;">
{{/* “Gradient” as stacked bands (sanitizer strips linear-gradient) */}}
<div style="position: absolute; inset: 0;">
<div style="position: absolute; top: 0; left: 0; right: 0; height: {{ $pRed }}%; background-color: {{ $color_red | safeCSS }};"></div>
<div style="position: absolute; top: {{ $pRed }}%; left: 0; right: 0; height: {{ sub $pYel $pRed }}%; background-color: {{ $color_yellow | safeCSS }};"></div>
<div style="position: absolute; top: {{ $pYel }}%; left: 0; right: 0; height: {{ sub $pBlu $pYel }}%; background-color: {{ $color_blue | safeCSS }};"></div>
<div style="position: absolute; top: {{ $pBlu }}%; left: 0; right: 0; height: {{ sub 100 $pBlu }}%; background-color: {{ $color_white | safeCSS }};"></div>
{{/* “Gradient” as stacked bands so Glance sanitizer wont kill it */}}
<div style="position:absolute; inset:0;">
<div style="position:absolute; top:0; left:0; right:0; height: {{ $pRed }}%; background-color: {{ $color_red | safeCSS }};"></div>
<div style="position:absolute; top:{{ $pRed }}%; left:0; right:0; height: {{ sub $pYel $pRed }}%; background-color: {{ $color_yellow | safeCSS }};"></div>
<div style="position:absolute; top:{{ $pYel }}%; left:0; right:0; height: {{ sub $pBlu $pYel }}%; background-color: {{ $color_blue | safeCSS }};"></div>
<div style="position:absolute; top:{{ $pBlu }}%; left:0; right:0; height: {{ sub 100 $pBlu }}%; background-color: {{ $color_white | safeCSS }};"></div>
</div>
{{ $top_pos := -2 }}
{{ $bot_pos := -2 }}
{{ $pos_thresh := 0.20 }}
@@ -580,17 +575,16 @@ data:
{{ else if and (lt (div $thisTempRange $temp_range) (mul $pos_thresh 2)) (gt (sub 1 $thisHighPct) $thisLowPct) }}
{{ $top_pos = -17 }}
{{ end }}
{{/* Overlay layer for numbers */}}
<div style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;
background-color: {{ $overlay_color | safeCSS }}; z-index: 1; border-radius: 10px;">
<p style='color: #F0F0F0; position: absolute; top: {{ $top_pos }}px; left: 0px; right: 0px'>{{ $thisHigh | toInt }}</p>
<p style='color: #F0F0F0; position: absolute; bottom: {{ $bot_pos }}px; left: 0px; right:0px'>{{ $thisLow | toInt }}</p>
</div>
</div>
{{ end }}
{{ end }}
</div>
</div>
</div>
# Calendar Widget
- type: calendar