feat(preview): implement preview mode for content management
- 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:
@@ -20,13 +20,22 @@ import { marked } from 'marked';
|
||||
|
||||
marked.setOptions({ gfm: true });
|
||||
|
||||
export const load: PageServerLoad = async ({ params, locals, url }) => {
|
||||
export const load: PageServerLoad = async ({ params, locals, 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 post = await getPostBySlug(slug, {
|
||||
locale: 'de',
|
||||
resolve: POST_RESOLVE,
|
||||
preview,
|
||||
});
|
||||
|
||||
if (!post) {
|
||||
@@ -202,6 +211,7 @@ export const load: PageServerLoad = async ({ params, locals, url }) => {
|
||||
|
||||
return {
|
||||
post,
|
||||
preview: !!preview,
|
||||
postImageUrl,
|
||||
rawPostImageUrl: postImageField?.url ?? null,
|
||||
postImageFocal: postImageField?.focal ?? null,
|
||||
|
||||
Reference in New Issue
Block a user