commerce/lib/sanity/utils/get-preview-url.ts
2023-08-14 12:24:07 +02:00

20 lines
648 B
TypeScript

// @ts-nocheck
import {isDev, SanityDocument} from 'sanity'
import { localStorefrontPreviewUrl, publicStorefrontPreviewUrl } from '../constants'
// Customise this function to show the correct URL based on the current document
export default function getPreviewUrl(doc: SanityDocument) {
if (isDev) {
if (!doc.slug) {
return
}
return `${localStorefrontPreviewUrl}?slug=${doc.slug.current}&locale=${doc.language}&secret=secret&type=${doc._type}`
} else {
if (!doc.slug) {
return
}
return `${publicStorefrontPreviewUrl}?slug=${doc.slug.current}&locale=${doc.language}&secret=secret&type=${doc._type}`
}
}