Runtime Engine Fix
This commit is contained in:
@@ -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) }}
|
||||
|
||||
<div id="conversionform"
|
||||
class="bg-white p-8 rounded-lg shadow-md w-full
|
||||
dark:bg-gray-700 dark:text-grey-200"
|
||||
x-data="navActions()">
|
||||
<div x-data="createConverter('{{ .Params.engine }}',
|
||||
{{ $config | safeJS }})"
|
||||
x-init="init()">
|
||||
|
||||
<h1 id="headline"
|
||||
class="text-2xl font-bold mb-6 text-center">
|
||||
{{ .Params.from_name }} in {{ .Params.to_name }}
|
||||
umrechnen
|
||||
</h1>
|
||||
<div id="conversionform"
|
||||
class="bg-white p-8 rounded-lg shadow-md w-full
|
||||
dark:bg-gray-700 dark:text-grey-200"
|
||||
x-data="navActions()">
|
||||
|
||||
<div>
|
||||
|
||||
<a x-ref="ajaxLink"
|
||||
x-target.push="maincontent"
|
||||
href="/"
|
||||
class="hidden"></a>
|
||||
<h1 id="headline"
|
||||
class="text-2xl font-bold mb-6 text-center">
|
||||
{{ .Params.from_name }} in {{ .Params.to_name }}
|
||||
umrechnen
|
||||
</h1>
|
||||
|
||||
<div>
|
||||
<label for="type"
|
||||
class="block text-sm font-medium opacity-75">
|
||||
Einheitentyp:
|
||||
</label>
|
||||
<select id="type" name="type"
|
||||
@change="navigate($event.target.value)"
|
||||
class="select mt-1 block w-full">
|
||||
{{ range $slug, $data := hugo.Data }}
|
||||
{{ if and $data.slug $data.name }}
|
||||
{{ $catUrl := partial "category-url.html"
|
||||
(dict "category" $data.slug
|
||||
"units" $data.units) }}
|
||||
<option
|
||||
value="{{ $catUrl }}"
|
||||
{{ if eq $data.slug
|
||||
$.Params.category }}selected{{ end }}>
|
||||
{{ $data.name }}
|
||||
</option>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col sm:flex-row items-center gap-4
|
||||
mt-4">
|
||||
<a x-ref="ajaxLink"
|
||||
x-target.push="maincontent"
|
||||
href="/"
|
||||
class="hidden"></a>
|
||||
|
||||
<div class="flex-1 w-full">
|
||||
<label for="from"
|
||||
<div>
|
||||
<label for="type"
|
||||
class="block text-sm font-medium opacity-75">
|
||||
Umrechnen von:
|
||||
Einheitentyp:
|
||||
</label>
|
||||
<select id="from" name="from"
|
||||
@change="navigateWithValue($event.target.value)"
|
||||
<select id="type" name="type"
|
||||
@change="navigate($event.target.value)"
|
||||
class="select mt-1 block w-full">
|
||||
{{ range $unit, $unitData := $availableUnits }}
|
||||
{{ if ne $unit $.Params.to }}
|
||||
{{ range $slug, $data := hugo.Data }}
|
||||
{{ if and $data.slug $data.name }}
|
||||
{{ $catUrl := partial "category-url.html"
|
||||
(dict "category" $data.slug
|
||||
"units" $data.units) }}
|
||||
<option
|
||||
value="/{{ $unit }}-in-{{ $.Params.to }}/"
|
||||
{{ if eq $unit
|
||||
$.Params.from }}selected{{ end }}>
|
||||
{{ $unitData.name }}
|
||||
value="{{ $catUrl }}"
|
||||
{{ if eq $data.slug
|
||||
$.Params.category }}selected{{ end }}>
|
||||
{{ $data.name }}
|
||||
</option>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="text-center sm:pt-6">
|
||||
<button type="button"
|
||||
@click="navigateWithResult(
|
||||
$el.dataset.swapUrl)"
|
||||
data-swap-url="/{{ .Params.to }}-in-{{ .Params.from }}/"
|
||||
class="inline-flex items-center text-sm
|
||||
font-medium text-primary
|
||||
dark:text-primary-light">
|
||||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none" viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
class="w-6 h-6">
|
||||
<path stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M7.5 21 3 16.5m0 0L7.5 12M3
|
||||
16.5h13.5m0-13.5L21 7.5m0
|
||||
0L16.5 12M21 7.5H7.5" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div class="flex flex-col sm:flex-row items-center gap-4
|
||||
mt-4">
|
||||
|
||||
<div class="flex-1 w-full">
|
||||
<label for="from"
|
||||
class="block text-sm font-medium
|
||||
opacity-75">
|
||||
Umrechnen von:
|
||||
</label>
|
||||
<select id="from" name="from"
|
||||
@change="navigateWithValue(
|
||||
$event.target.value)"
|
||||
class="select mt-1 block w-full">
|
||||
{{ range $unit, $unitData := $availableUnits }}
|
||||
{{ if ne $unit $.Params.to }}
|
||||
<option
|
||||
value="/{{ $unit }}-in-{{ $.Params.to }}/"
|
||||
{{ if eq $unit
|
||||
$.Params.from }}selected{{ end }}>
|
||||
{{ $unitData.name }}
|
||||
</option>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="text-center sm:pt-6">
|
||||
<button type="button"
|
||||
@click="navigateWithResult(
|
||||
$el.dataset.swapUrl)"
|
||||
data-swap-url="/{{ .Params.to }}-in-{{ .Params.from }}/"
|
||||
class="inline-flex items-center text-sm
|
||||
font-medium text-primary
|
||||
dark:text-primary-light">
|
||||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none" viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
class="w-6 h-6">
|
||||
<path stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M7.5 21 3 16.5m0 0L7.5 12M3
|
||||
16.5h13.5m0-13.5L21 7.5m0
|
||||
0L16.5 12M21 7.5H7.5" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 w-full">
|
||||
<label for="to"
|
||||
class="block text-sm font-medium
|
||||
opacity-75">
|
||||
Umrechnen in:
|
||||
</label>
|
||||
<select id="to" name="to"
|
||||
@change="navigateWithValue(
|
||||
$event.target.value)"
|
||||
class="select mt-1 block w-full">
|
||||
{{ range $unit, $unitData := $availableUnits }}
|
||||
{{ if ne $unit $.Params.from }}
|
||||
<option
|
||||
value="/{{ $.Params.from }}-in-{{ $unit }}/"
|
||||
{{ if eq $unit
|
||||
$.Params.to }}selected{{ end }}>
|
||||
{{ $unitData.name }}
|
||||
</option>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 w-full">
|
||||
<label for="to"
|
||||
class="block text-sm font-medium opacity-75">
|
||||
Umrechnen in:
|
||||
</label>
|
||||
<select id="to" name="to"
|
||||
@change="navigateWithValue($event.target.value)"
|
||||
class="select mt-1 block w-full">
|
||||
{{ range $unit, $unitData := $availableUnits }}
|
||||
{{ if ne $unit $.Params.from }}
|
||||
<option
|
||||
value="/{{ $.Params.from }}-in-{{ $unit }}/"
|
||||
{{ if eq $unit
|
||||
$.Params.to }}selected{{ end }}>
|
||||
{{ $unitData.name }}
|
||||
</option>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div x-data="createConverter('{{ .Params.engine }}',
|
||||
{{ $config | safeJS }})"
|
||||
x-init="init()">
|
||||
|
||||
<div class="flex flex-col sm:flex-row gap-4 mt-4">
|
||||
<div class="flex-1">
|
||||
<label for="value"
|
||||
class="block text-sm font-medium
|
||||
opacity-75">
|
||||
class="block text-sm font-medium opacity-75">
|
||||
Wert in {{ .Params.from_name }}:
|
||||
</label>
|
||||
<input type="text" id="value"
|
||||
@@ -155,8 +159,7 @@
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<label for="result"
|
||||
class="block text-sm font-medium
|
||||
opacity-75">
|
||||
class="block text-sm font-medium opacity-75">
|
||||
Ergebnis in {{ .Params.to_name }}:
|
||||
</label>
|
||||
<input type="text" id="result"
|
||||
@@ -173,13 +176,13 @@
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div id="formula" class="mt-4">
|
||||
{{ partial "conversion-formula.html" . }}
|
||||
</div>
|
||||
<div id="info">
|
||||
{{ partial "conversion-seo-texts.html" . }}
|
||||
</div>
|
||||
|
||||
<div id="formula" class="mt-4">
|
||||
{{ partial "conversion-formula.html" . }}
|
||||
</div>
|
||||
<div id="info">
|
||||
{{ partial "conversion-seo-texts.html" . }}
|
||||
</div>
|
||||
|
||||
{{ end }}
|
||||
|
||||
Reference in New Issue
Block a user