Files
supabase/apps/cms/src/utilities/generatePreviewPath.ts
T
Francesco SansalvadoreandIvan Vasilov f7d90bbc30 feat: new cms app (#35999)
* add cms turbo app

* add cms scripts to package.json

* update README

* update README

* update files

* fix formatting

* fix populateAuthors

* sync dependencies

* update launch week field

* update lint config

* Coordinate the deps to be the same as the other apps.

* Remove extra files.

* Run prettier on the CMS files.

* Add commands for cleaning and typechecking.

* Fix weird version of @types/react in docs.

* run pnpm install

* fix pnpm-lock

* fix cms lint

---------

Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2025-06-03 14:26:43 +03:00

32 lines
805 B
TypeScript

import { PayloadRequest, CollectionSlug } from 'payload'
const collectionPrefixMap: Partial<Record<CollectionSlug, string>> = {
posts: '/blog',
pages: '',
}
type Props = {
collection: keyof typeof collectionPrefixMap
slug: string
req: PayloadRequest
}
export const generatePreviewPath = ({ collection, slug }: Props) => {
if (collection === 'posts') {
const baseUrl = process.env.BLOG_APP_URL || 'http://localhost:3000'
// Use our preview API route for post previews
return `${baseUrl}/api/preview?slug=${slug}`
}
const encodedParams = new URLSearchParams({
slug,
collection,
path: `${collectionPrefixMap[collection]}/${slug}`,
previewSecret: process.env.PREVIEW_SECRET || '',
})
const url = `/next/preview?${encodedParams.toString()}`
return url
}