From ec56a231e9c989391110a8f6f633fb49fdb0b028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BChlinghaus?= Date: Fri, 29 May 2026 23:03:50 +0200 Subject: [PATCH] Runtime Engine Fix --- hugo/layouts/conversion/single.html | 217 +++++++++--------- hugo/layouts/partials/conversion-formula.html | 47 ++-- hugo/static/js/converter.js | 13 +- 3 files changed, 152 insertions(+), 125 deletions(-) diff --git a/hugo/layouts/conversion/single.html b/hugo/layouts/conversion/single.html index 86a124a..2079bc7 100644 --- a/hugo/layouts/conversion/single.html +++ b/hugo/layouts/conversion/single.html @@ -16,134 +16,138 @@ {{ $fromCode := .Params.from }} {{ $toCode := .Params.to }} {{ $config = printf - "{ init: async function () { const pbUrl = document.querySelector('meta[name=\\'pocketbase-url\\']')?.content || 'https://www.alphabreed.com'; try { const response = await fetch(`${pbUrl}/api/collections/currencies/records`); if (!response.ok) { this.ratesError = 'Wechselkurse konnten nicht geladen werden.'; return; } const data = await response.json(); for (const item of data.items || []) { this.rates[item.id] = item.rate; } } catch (e) { this.ratesError = 'Wechselkurse konnten nicht geladen werden.'; } }, convert: function (value) { const fromRate = '%s' === 'eur' ? 1 : this.rates['%s']; const toRate = '%s' === 'eur' ? 1 : this.rates['%s']; if (!fromRate || !toRate) { return null; } return value.times(new Decimal(toRate)).dividedBy(new Decimal(fromRate)); } }" + "{ init: async function () { const pbUrl = document.querySelector('meta[name=\\'pocketbase-url\\']')?.content || 'https://www.alphabreed.com'; try { const response = await fetch(`${pbUrl}/api/collections/currencies/records`); if (!response.ok) { this.ratesError = 'Wechselkurse konnten nicht geladen werden.'; return; } const data = await response.json(); let latestUpdate = ''; for (const item of data.items || []) { this.rates[item.id] = item.rate; if (!latestUpdate || item.updated > latestUpdate) { latestUpdate = item.updated; } } const fromRate = '%s' === 'eur' ? 1 : this.rates['%s']; const toRate = '%s' === 'eur' ? 1 : this.rates['%s']; if (fromRate && toRate) { this.currentRate = parseFloat(toRate) / parseFloat(fromRate); } if (latestUpdate) { this.ratesUpdated = new Date(latestUpdate).toLocaleString('de-DE', { day: '2-digit', month: 'long', year: 'numeric', hour: '2-digit', minute: '2-digit' }); } } catch (e) { this.ratesError = 'Wechselkurse konnten nicht geladen werden.'; } }, convert: function (value) { const fromRate = '%s' === 'eur' ? 1 : this.rates['%s']; const toRate = '%s' === 'eur' ? 1 : this.rates['%s']; if (!fromRate || !toRate) { return null; } return value.times(new Decimal(toRate)).dividedBy(new Decimal(fromRate)); } }" + $fromCode $fromCode $toCode $toCode $fromCode $fromCode $toCode $toCode }} {{ end }} {{ $availableUnits := partial "available-units.html" (dict "category" .Params.category "units" $catData.units) }} -
+
-

- {{ .Params.from_name }} in {{ .Params.to_name }} - umrechnen -

+
-
- - +

+ {{ .Params.from_name }} in {{ .Params.to_name }} + umrechnen +

- - -
-
+ -
-
-
- -
+
+ +
+ + +
+ +
+ +
+ +
+ + +
-
- -
-
- -
-
-
+
+ {{ partial "conversion-formula.html" . }} +
+
+ {{ partial "conversion-seo-texts.html" . }} +
-
- {{ partial "conversion-formula.html" . }} -
-
- {{ partial "conversion-seo-texts.html" . }}
{{ end }} diff --git a/hugo/layouts/partials/conversion-formula.html b/hugo/layouts/partials/conversion-formula.html index 0196cde..05cccb2 100644 --- a/hugo/layouts/partials/conversion-formula.html +++ b/hugo/layouts/partials/conversion-formula.html @@ -49,27 +49,40 @@

{{ end }} {{ else if eq .Params.engine "runtime" }} - {{ $rate := float .Params.rate }}

Die Umrechnung von {{ $fromName }} in {{ $toName }} erfolgt mittels dieser Formel:

- {{ if ge $rate 1 }} -

- {{ $toName }} = {{ $fromName }} × - {{ printf "%.12g" $rate }} +

+

+

- {{ else }} - {{ $invRate := div 1 $rate }} -

- {{ $toName }} = {{ $fromName }} / - {{ printf "%.12g" $invRate }} +

+

- {{ end }} - {{ with .Params.rates_updated }} -

- Wechselkurs zuletzt aktualisiert: - {{ time.Format "2. Januar 2006, 15:04" . }} -

- {{ end }} +
+
+ {{ $rate := float .Params.rate }} + {{ if ge $rate 1 }} +

+ {{ $toName }} = {{ $fromName }} × + {{ printf "%.12g" $rate }} +

+ {{ else }} + {{ $invRate := div 1 $rate }} +

+ {{ $toName }} = {{ $fromName }} / + {{ printf "%.12g" $invRate }} +

+ {{ end }} +
+

+ Wechselkurs zuletzt aktualisiert: + +

{{ end }} diff --git a/hugo/static/js/converter.js b/hugo/static/js/converter.js index 682086a..5d97e22 100644 --- a/hugo/static/js/converter.js +++ b/hugo/static/js/converter.js @@ -41,6 +41,8 @@ function createConverter(engine, config) { result: '', rates: {}, ratesError: '', + ratesUpdated: '', + currentRate: 0, async init() { const params = new URLSearchParams( window.location.search); @@ -110,7 +112,16 @@ function createConverter(engine, config) { function prettyNumber(num, minPrecision, maxPrecision) { minPrecision = minPrecision || 4; maxPrecision = maxPrecision || 10; - const d = new Decimal(num); + const val = num instanceof Decimal ? num.toNumber() : Number(num); + if (!Number.isFinite(val)) { + return ''; + } + let d; + try { + d = new Decimal(num); + } catch (e) { + return ''; + } const absVal = d.abs(); // Larger numbers need fewer decimal places for readable output; // smaller numbers get more to stay meaningful.