Files
windwiderstand/src/lib/components/BlockRenderer.svelte
T
Peter Meier 63a9721841
Deploy / verify (push) Successful in 51s
Deploy / deploy (push) Successful in 53s
feat(embed): standalone widget route /widget/<collection>/<slug>
Renders a single CMS entry as a block in isolation — no header, footer, or
preview banner. Lets us share a deep link to a single widget (e.g. the live
strommix gauge) for embedding or quick previews without exposing the rest of
the page.

- New BlockRenderer.svelte: switch over `_type` shared with ContentRows.
- Generic `getEntryBySlug(collection, slug, options)` in cms.ts so any
  collection (live_strommix, deadline_banner, image, ...) is fetchable.
- Route group `(embed)/+layout@.svelte` resets the layout chain so no
  Header/Footer/TopBanner inherit. `x-robots-tag: noindex`.
- Optional `?preview=<token>` for drafts. Cache: short s-maxage for live,
  no-store for preview.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-05 09:37:21 +02:00

96 lines
3.9 KiB
Svelte

<script lang="ts">
import MarkdownBlock from "./blocks/MarkdownBlock.svelte";
import HeadlineBlock from "./blocks/HeadlineBlock.svelte";
import HtmlBlock from "./blocks/HtmlBlock.svelte";
import IframeBlock from "./blocks/IframeBlock.svelte";
import ImageBlock from "./blocks/ImageBlock.svelte";
import ImageGalleryBlock from "./blocks/ImageGalleryBlock.svelte";
import FilesBlock from "./blocks/FilesBlock.svelte";
import YoutubeVideoBlock from "./blocks/YoutubeVideoBlock.svelte";
import YoutubeVideoGalleryBlock from "./blocks/YoutubeVideoGalleryBlock.svelte";
import QuoteBlock from "./blocks/QuoteBlock.svelte";
import QuoteCarouselBlock from "./blocks/QuoteCarouselBlock.svelte";
import LinkListBlock from "./blocks/LinkListBlock.svelte";
import PostOverviewBlock from "./blocks/PostOverviewBlock.svelte";
import SearchableTextBlock from "./blocks/SearchableTextBlock.svelte";
import CalendarBlock from "./blocks/CalendarBlock.svelte";
import OrganisationsBlock from "./blocks/OrganisationsBlock.svelte";
import OpnFormBlock from "./blocks/OpnFormBlock.svelte";
import DeadlineBannerBlock from "./blocks/DeadlineBannerBlock.svelte";
import StrommixBlock from "./blocks/StrommixBlock.svelte";
import type { Translations } from "$lib/translations";
import type {
ResolvedBlock,
MarkdownBlockData,
HeadlineBlockData,
HtmlBlockData,
IframeBlockData,
ImageBlockData,
ImageGalleryBlockData,
FilesBlockData,
YoutubeVideoBlockData,
YoutubeVideoGalleryBlockData,
QuoteBlockData,
QuoteCarouselBlockData,
LinkListBlockData,
PostOverviewBlockData,
SearchableTextBlockData,
CalendarBlockData,
OrganisationsBlockData,
OpnFormBlockData,
DeadlineBannerBlockData,
LiveStrommixBlockData,
} from "$lib/block-types";
let {
block,
translations = {},
}: { block: ResolvedBlock; translations?: Translations | null } = $props();
const type = $derived((block._type as string) ?? "unknown");
</script>
{#if type === "markdown"}
<MarkdownBlock block={block as MarkdownBlockData} />
{:else if type === "headline"}
<HeadlineBlock block={block as HeadlineBlockData} />
{:else if type === "html"}
<HtmlBlock block={block as HtmlBlockData} />
{:else if type === "iframe"}
<IframeBlock block={block as IframeBlockData} translations={translations} />
{:else if type === "image"}
<ImageBlock block={block as ImageBlockData} />
{:else if type === "image_gallery"}
<ImageGalleryBlock block={block as ImageGalleryBlockData} />
{:else if type === "files"}
<FilesBlock block={block as FilesBlockData} />
{:else if type === "youtube_video"}
<YoutubeVideoBlock block={block as YoutubeVideoBlockData} />
{:else if type === "youtube_video_gallery"}
<YoutubeVideoGalleryBlock block={block as YoutubeVideoGalleryBlockData} />
{:else if type === "quote"}
<QuoteBlock block={block as QuoteBlockData} />
{:else if type === "quote_carousel"}
<QuoteCarouselBlock block={block as QuoteCarouselBlockData} />
{:else if type === "link_list"}
<LinkListBlock block={block as LinkListBlockData} />
{:else if type === "post_overview"}
<PostOverviewBlock block={block as PostOverviewBlockData} />
{:else if type === "searchable_text"}
<SearchableTextBlock block={block as SearchableTextBlockData} translations={translations} />
{:else if type === "calendar"}
<CalendarBlock block={block as CalendarBlockData} translations={translations} />
{:else if type === "organisations"}
<OrganisationsBlock block={block as OrganisationsBlockData} />
{:else if type === "opnform"}
<OpnFormBlock block={block as OpnFormBlockData} />
{:else if type === "deadline_banner"}
<DeadlineBannerBlock block={block as DeadlineBannerBlockData} />
{:else if type === "live_strommix"}
<StrommixBlock block={block as LiveStrommixBlockData} />
{:else}
<div class="rounded border border-erde-200 bg-erde-50 px-3 py-2 text-sm text-erde-800">
Unbekannter Block: <code>{type}</code>
</div>
{/if}