diff --git a/src/lib/components/Accordion.svelte b/src/lib/components/Accordion.svelte index dbe15c1..582f78a 100644 --- a/src/lib/components/Accordion.svelte +++ b/src/lib/components/Accordion.svelte @@ -3,27 +3,43 @@ import Icon from "@iconify/svelte"; import "$lib/iconify-offline"; + interface Props { + label: string; + open?: boolean; + lazy?: boolean; + id?: string; + class?: string; + onToggleEvent?: (e: Event) => void; + children: Snippet; + } + let { label, open = false, + lazy = false, id = undefined, class: cls = "", + onToggleEvent, children, - }: { - label: string; - open?: boolean; - id?: string; - class?: string; - children: Snippet; - } = $props(); + }: Props = $props(); + + let everOpened = $state(false); + const mounted = $derived(!lazy || open || everOpened); + + function onToggle(e: Event) { + if ((e.target as HTMLDetailsElement).open) everOpened = true; + onToggleEvent?.(e); + } -
+
{label}
- {@render children()} + {#if mounted} + {@render children()} + {/if}
diff --git a/src/lib/components/CommentCountBadge.svelte b/src/lib/components/CommentCountBadge.svelte new file mode 100644 index 0000000..1ff0862 --- /dev/null +++ b/src/lib/components/CommentCountBadge.svelte @@ -0,0 +1,62 @@ + + + + + {count ?? "…"} + diff --git a/src/lib/components/Comments.svelte b/src/lib/components/Comments.svelte new file mode 100644 index 0000000..8c5872a --- /dev/null +++ b/src/lib/components/Comments.svelte @@ -0,0 +1,394 @@ + + +
+ {#if loading && comments.length === 0} +

Lade Kommentare …

+ {:else if loadError} +

Fehler: {loadError}

+ {:else} + {#if topLevel.length === 0} +

Noch keine Kommentare. Sei der erste.

+ {/if} + + + +
+

Kommentar schreiben

+ + + + {#if submitError}

{submitError}

{/if} + {#if requireApproval} +

Kommentare werden vor Veröffentlichung geprüft.

+ {/if} + +
+ {/if} +
diff --git a/src/routes/post/[slug]/+page.server.ts b/src/routes/post/[slug]/+page.server.ts index e2baa12..fff18ca 100644 --- a/src/routes/post/[slug]/+page.server.ts +++ b/src/routes/post/[slug]/+page.server.ts @@ -1,5 +1,5 @@ import type { PageServerLoad } from './$types'; -import { getPostBySlug, getPageConfigBySlug, getPageConfigs } from '$lib/cms'; +import { getPostBySlug } from '$lib/cms'; import { resolveContentImages, ensureTransformedImage, @@ -135,16 +135,6 @@ export const load: PageServerLoad = async ({ params, locals, url, setHeaders }) ? `https://www.openstreetmap.org/search?query=${encodeURIComponent(eventLocation.text)}` : null; - const pageConfig = - (await getPageConfigBySlug('page-config-default', { locale: 'de' })) ?? - (await getPageConfigs({ locale: 'de', per_page: 1 }))[0] ?? - null; - const commentSlotRaw = - (pageConfig as { postCommentSlot?: string } | null)?.postCommentSlot ?? ''; - const commentSlot = commentSlotRaw - .replace(/\{\{PAGE_ID\}\}/g, slug) - .replace(/\{\{PAGE_URL\}\}/g, url.href) - .replace(/\{\{PAGE_TITLE\}\}/g, post.headline ?? post.linkName ?? slug); const showCommentSection = (post as { showCommentSection?: boolean }).showCommentSection !== false; const jsonLd: Record[] = []; @@ -263,7 +253,7 @@ export const load: PageServerLoad = async ({ params, locals, url, setHeaders }) eventLocationText: eventLocation?.text ?? null, mapEmbedUrl, mapLinkUrl, - commentSlot: showCommentSection ? commentSlot : '', + commentPageId: showCommentSection ? slug : null, translations, seoTitle: post.seoTitle ?? postHeadline, seoDescription: postDescription, diff --git a/src/routes/post/[slug]/+page.svelte b/src/routes/post/[slug]/+page.svelte index b13fbe1..49fac09 100644 --- a/src/routes/post/[slug]/+page.svelte +++ b/src/routes/post/[slug]/+page.svelte @@ -5,21 +5,13 @@ import EventBadges from '$lib/components/EventBadges.svelte'; import EventMap from '$lib/components/EventMap.svelte'; import Accordion from '$lib/components/Accordion.svelte'; + import CommentCountBadge from '$lib/components/CommentCountBadge.svelte'; + import Comments from '$lib/components/Comments.svelte'; import RustyImage from '$lib/components/RustyImage.svelte'; import { t, T } from '$lib/translations'; import type { PageData } from './$types'; let { data }: { data: PageData } = $props(); - - function executeScripts(node: HTMLElement) { - const scripts = node.querySelectorAll("script"); - scripts.forEach((old) => { - const s = document.createElement("script"); - for (const { name, value } of old.attributes) s.setAttribute(name, value); - s.text = old.textContent ?? ""; - old.replaceWith(s); - }); - } @@ -34,7 +26,7 @@
{#if data.rawPostImageUrl} -
+
{:else if data.postImageUrl} -
+
{/if}
- {#if data.postDate} + {#if data.postDate || data.commentPageId}
- + {#if data.postDate} + + {/if} + {#if data.commentPageId} + + {/if}
{/if}
@@ -148,10 +145,10 @@ /> {/if} -{#if data.commentSlot} - -
- {@html data.commentSlot} +{#if data.commentPageId} + +
+
{/if}