import React from 'react'; import { Page } from './_util'; import { useParams } from 'react-router-dom'; export default function LegalPage() { const { page } = useParams(); const [loading, setLoading] = React.useState(true); const [title, setTitle] = React.useState(''); const [body, setBody] = React.useState(''); React.useEffect(() => { async function load() { setLoading(true); const res = await fetch(`/api/v1/legal/${encodeURIComponent(page || '')}?lang=de`, { headers: { 'Cache-Control': 'no-store' }}); if (res.ok) { const j = await res.json(); setTitle(j.title || ''); setBody(j.body_markdown || ''); } setLoading(false); } if (page) load(); }, [page]); return ( {loading ? Lädt… : } ); } function Markdown({ md }: { md: string }) { // Tiny, safe Markdown: paragraphs + basic bold/italic + links; no external dependency const html = React.useMemo(() => { let s = md .replace(/&/g, '&') .replace(//g, '>'); // bold **text** s = s.replace(/\*\*(.+?)\*\*/g, '$1'); // italic *text* s = s.replace(/(?$1'); // links [text](url) s = s.replace(/\[(.+?)\]\((https?:[^\s)]+)\)/g, '$1<\/a>'); // paragraphs s = s.split(/\n{2,}/).map(p => `${p.replace(/\n/g, '')}<\/p>`).join('\n'); return s; }, [md]); return ; }
Lädt…
${p.replace(/\n/g, '')}<\/p>`).join('\n'); return s; }, [md]); return