diff --git a/.changeset/fix-preview-url-pattern.md b/.changeset/fix-preview-url-pattern.md new file mode 100644 index 0000000..53369c7 --- /dev/null +++ b/.changeset/fix-preview-url-pattern.md @@ -0,0 +1,6 @@ +--- +"@emdash-cms/admin": patch +"emdash": patch +--- + +fix(admin): use collection urlPattern for preview button fallback URL diff --git a/packages/admin/src/components/ContentEditor.tsx b/packages/admin/src/components/ContentEditor.tsx index d7ddf01..d55d82e 100644 --- a/packages/admin/src/components/ContentEditor.tsx +++ b/packages/admin/src/components/ContentEditor.tsx @@ -363,6 +363,11 @@ export function ContentEditor({ const handlePreview = async () => { if (!item?.id) return; + const contentUrl = (s: string) => { + const pattern = manifest?.collections[collection]?.urlPattern; + return pattern ? pattern.replace("{slug}", s) : `/${collection}/${s}`; + }; + setIsLoadingPreview(true); try { const result = await getPreviewUrl(collection, item.id); @@ -371,11 +376,11 @@ export function ContentEditor({ window.open(result.url, "_blank", "noopener,noreferrer"); } else { // Fallback to direct URL if preview not configured - window.open(`/${collection}/${slug || item.id}`, "_blank", "noopener,noreferrer"); + window.open(contentUrl(slug || item.id), "_blank", "noopener,noreferrer"); } } catch { // Fallback to direct URL on error - window.open(`/${collection}/${slug || item?.id}`, "_blank", "noopener,noreferrer"); + window.open(contentUrl(slug || item?.id || ""), "_blank", "noopener,noreferrer"); } finally { setIsLoadingPreview(false); } diff --git a/packages/admin/src/lib/api/client.ts b/packages/admin/src/lib/api/client.ts index 721b113..b46a849 100644 --- a/packages/admin/src/lib/api/client.ts +++ b/packages/admin/src/lib/api/client.ts @@ -55,6 +55,7 @@ export interface AdminManifest { labelSingular: string; supports: string[]; hasSeo: boolean; + urlPattern?: string; fields: Record< string, { diff --git a/packages/core/src/astro/types.ts b/packages/core/src/astro/types.ts index c216b12..e5b8b6f 100644 --- a/packages/core/src/astro/types.ts +++ b/packages/core/src/astro/types.ts @@ -28,6 +28,7 @@ export interface ManifestCollection { labelSingular: string; supports: string[]; hasSeo: boolean; + urlPattern?: string; fields: Record< string, { diff --git a/packages/core/src/emdash-runtime.ts b/packages/core/src/emdash-runtime.ts index e5a7411..810b0bb 100644 --- a/packages/core/src/emdash-runtime.ts +++ b/packages/core/src/emdash-runtime.ts @@ -1180,6 +1180,7 @@ export class EmDashRuntime { labelSingular: collection.labelSingular || collection.label, supports: collection.supports || [], hasSeo: collection.hasSeo, + urlPattern: collection.urlPattern, fields, }; }