feat(comments): Auto-open accordion wenn Kommentare vorhanden, Pages-Support
- Post: Kommentar-Count server-seitig laden, Accordion offen wenn count > 0 - Page-Route: optionale Kommentare via commentsEnabled-Flag (Schema: default false) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { getPageBySlug } from '$lib/cms';
|
||||
import { getPageBySlug, getCommentCounts } from '$lib/cms';
|
||||
import {
|
||||
extractCmsImageField,
|
||||
ensureTransformedImage,
|
||||
@@ -130,9 +130,17 @@ export const load: PageServerLoad = async ({ params, locals, fetch, url, setHead
|
||||
}
|
||||
}
|
||||
|
||||
const commentsEnabled = !!(page as { commentsEnabled?: boolean }).commentsEnabled;
|
||||
const commentPageId = commentsEnabled ? (page._slug ?? slug) : null;
|
||||
const commentCount = commentPageId
|
||||
? (await getCommentCounts([commentPageId]))[commentPageId] ?? 0
|
||||
: 0;
|
||||
|
||||
return {
|
||||
page,
|
||||
translations,
|
||||
commentPageId,
|
||||
commentCount,
|
||||
preview: !!preview,
|
||||
previewDraft: !!previewDraft,
|
||||
seoTitle: page.seoTitle ?? page.headline ?? page.linkName ?? slug,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<script lang="ts">
|
||||
import ContentRows from '$lib/components/ContentRows.svelte';
|
||||
import Accordion from '$lib/components/Accordion.svelte';
|
||||
import Comments from '$lib/components/Comments.svelte';
|
||||
import type { PageData } from './$types';
|
||||
|
||||
let { data }: { data: PageData } = $props();
|
||||
@@ -15,3 +17,19 @@
|
||||
<article>
|
||||
<ContentRows layout={data.page} translations={data.translations} />
|
||||
</article>
|
||||
|
||||
{#if data.commentPageId}
|
||||
<div class="print:hidden">
|
||||
<Accordion
|
||||
id="comments-section"
|
||||
label="Kommentare"
|
||||
lazy
|
||||
open={data.commentCount > 0}
|
||||
class="mt-6"
|
||||
>
|
||||
<div class="p-8 border border-stein-200 rounded-lg">
|
||||
<Comments pageId={data.commentPageId} />
|
||||
</div>
|
||||
</Accordion>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { getPostBySlug } from '$lib/cms';
|
||||
import { getPostBySlug, getCommentCounts } from '$lib/cms';
|
||||
import {
|
||||
resolveContentImages,
|
||||
ensureTransformedImage,
|
||||
@@ -298,6 +298,7 @@ export const load: PageServerLoad = async ({ params, locals, url, setHeaders })
|
||||
mapEmbedUrl,
|
||||
mapLinkUrl,
|
||||
commentPageId: showCommentSection ? slug : null,
|
||||
commentCount: showCommentSection ? (await getCommentCounts([slug]))[slug] ?? 0 : 0,
|
||||
canonicalUrl: canonical,
|
||||
readingTimeMinutes,
|
||||
translations,
|
||||
|
||||
@@ -161,6 +161,7 @@
|
||||
id="comments-section"
|
||||
label={t(data.translations, T.post_comments)}
|
||||
lazy
|
||||
open={data.commentCount > 0}
|
||||
class="mt-6"
|
||||
>
|
||||
<div class="p-8 border border-stein-200 rounded-lg">
|
||||
|
||||
Reference in New Issue
Block a user