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>(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)._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 }; };