diff --git a/web/src/routes/markt/[slug]/+page.svelte b/web/src/routes/markt/[slug]/+page.svelte index 8c30f48..2383a0a 100644 --- a/web/src/routes/markt/[slug]/+page.svelte +++ b/web/src/routes/markt/[slug]/+page.svelte @@ -31,6 +31,80 @@ : null ); + interface ParsedPriceEntry { + category: string; + price: string; + } + + interface ParsedPriceGroup { + label: string; + entries: ParsedPriceEntry[]; + } + + const categoryLabels: Record = { + Erw: 'Erwachsene', + 'Erw.': 'Erwachsene', + Erm: 'Ermäßigt', + 'Erm.': 'Ermäßigt' + }; + + function parseAdmissionNotes(notes: string): { + groups: ParsedPriceGroup[]; + remaining: string; + } { + const groups: ParsedPriceGroup[] = []; + const remainingParts: string[] = []; + + // Split on ". " followed by uppercase — avoids breaking on "Erw." abbreviation + const segments = notes.split(/\.\s+(?=[A-ZÄÖÜ])/).filter((s) => s.trim()); + + for (const raw of segments) { + const segment = raw.replace(/\.+$/, '').trim(); + const colonIdx = segment.indexOf(':'); + if (colonIdx === -1) { + remainingParts.push(segment); + continue; + } + + const label = segment.substring(0, colonIdx).trim(); + const pricesStr = segment.substring(colonIdx + 1).trim(); + + // If pricesStr contains colons, it's "Cat: Price, Cat: Price" format — skip parsing + if (pricesStr.includes(':')) { + remainingParts.push(segment); + continue; + } + + const entries: ParsedPriceEntry[] = []; + // Category must start with a letter (prevents matching bare prices like "13,00 €") + const pricePattern = /(?:^|,\s*)([A-Za-zÄÖÜäöüß].*?)\s+(\d+(?:,\d+)?)\s*€/g; + let m; + + while ((m = pricePattern.exec(pricesStr)) !== null) { + const cat = m[1].trim(); + entries.push({ + category: categoryLabels[cat] ?? cat, + price: m[2] + ' €' + }); + } + + if (entries.length > 0) { + groups.push({ label, entries }); + } else { + remainingParts.push(segment); + } + } + + return { + groups, + remaining: remainingParts.length > 0 ? remainingParts.join('. ') + '.' : '' + }; + } + + const parsedNotes = $derived( + admission?.notes ? parseAdmissionNotes(admission.notes) : { groups: [], remaining: '' } + ); + const jsonLdBreadcrumbHtml = $derived( '