feat(preview): implement preview mode for content management
Deploy / verify (push) Successful in 41s
Deploy / deploy (push) Successful in 1m3s

- Added support for a preview mode in the CMS, allowing draft content to be viewed without being indexed.
- Updated hooks and server logic to handle preview parameters, adjusting cache control and robots tags accordingly.
- Enhanced layout to display a preview notification when in preview mode, improving user experience for content editors.
This commit is contained in:
Peter Meier
2026-04-23 11:11:27 +02:00
parent 9216138a8c
commit 50bb0ef398
5 changed files with 61 additions and 7 deletions
+11 -1
View File
@@ -23,13 +23,22 @@ function focalToCss(focal: { x: number; y: number } | undefined): string | null
return `${(focal.x * 100).toFixed(2)}% ${(focal.y * 100).toFixed(2)}%`;
}
export const load: PageServerLoad = async ({ params, locals, fetch }) => {
export const load: PageServerLoad = async ({ params, locals, fetch, url, setHeaders }) => {
const { slug } = params;
const translations = locals.translations ?? {};
const preview = url.searchParams.get('preview') ?? undefined;
if (preview) {
setHeaders({
'cache-control': 'private, no-store, max-age=0',
'x-robots-tag': 'noindex, nofollow',
});
}
const page = await getPageBySlug(slug, {
locale: 'de',
resolve: PAGE_RESOLVE,
preview,
});
if (!page) {
@@ -78,6 +87,7 @@ export const load: PageServerLoad = async ({ params, locals, fetch }) => {
return {
page,
translations,
preview: !!preview,
seoTitle: page.seoTitle ?? page.headline ?? page.linkName ?? slug,
seoDescription: page.seoDescription ?? page.subheadline ?? '',
robots: (page as { seoMetaRobots?: string }).seoMetaRobots ?? undefined,