63a9721841
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>
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { error } from "@sveltejs/kit";
|
|
import { getEntryBySlug } from "$lib/cms";
|
|
import type { PageServerLoad } from "./$types";
|
|
|
|
export const load: PageServerLoad = async ({ params, url, setHeaders }) => {
|
|
const { collection, slug } = params;
|
|
const preview = url.searchParams.get("preview") ?? undefined;
|
|
const locale = url.searchParams.get("_locale") ?? undefined;
|
|
|
|
const entry = await getEntryBySlug<Record<string, unknown>>(collection, slug, {
|
|
resolve: ["all"],
|
|
preview,
|
|
locale,
|
|
});
|
|
if (!entry) throw error(404, `Entry not found: ${collection}/${slug}`);
|
|
|
|
// _type is needed by BlockRenderer's switch. Server backfills it from the
|
|
// route param so the renderer sees the same shape as inside a page row.
|
|
if (typeof entry._type !== "string") {
|
|
(entry as Record<string, unknown>)._type = collection;
|
|
}
|
|
|
|
// Embeds: skip search engines, mild caching for public reads.
|
|
setHeaders({
|
|
"x-robots-tag": "noindex",
|
|
"cache-control": preview
|
|
? "private, no-store"
|
|
: "public, s-maxage=60, stale-while-revalidate=300",
|
|
});
|
|
|
|
return { collection, slug, entry, preview: !!preview };
|
|
};
|