fix(cms): resolve internal CTA links per locale via a page selector (MITHOME-123)
The home hero CTA stored a free-text href "/kapcsolat" that predated the locale-prefixed routing (MITHOME-114), so the main call-to-action led to a 404. Internal targets were typed by hand and could never follow the locale or its translated slug. CTA links now choose between an internal page (home/about/services/ contact/privacy/terms) and an external URL. Page links are resolved per request with localePath(), giving /hu/kapcsolat and /en/contact; external links (webmail) keep their localized href. A Payload migration converts existing internal paths to page links on the published global and every draft/version, idempotently and independent of the locale migration's order. The global-doc iteration shared with MITHOME-111 moved to src/lib/migrate-global-docs.ts; the JSON seed emits the new shape too. Verified on a copy of the staging DB: both migrations ran on startup, /hu and /en CTAs point to their contact pages (200), webmail unchanged, admin shows the selector, toggles the fields and blocks publishing a URL link without a URL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
38d34fab4c
commit
e8ff7adeb5
@@ -34,6 +34,7 @@ import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { getPayload, type Payload } from 'payload'
|
||||
import config from '../src/payload.config'
|
||||
import { internalPathToPageKey } from '../src/lib/cta-link'
|
||||
|
||||
import homeJson from '../src/content/pages/home.json'
|
||||
import aboutJson from '../src/content/pages/about.json'
|
||||
@@ -51,12 +52,23 @@ function toStringArray(items: readonly string[]): { value: string }[] {
|
||||
return items.map((value) => ({ value }))
|
||||
}
|
||||
|
||||
type CtaJson = { text: string; href: string; external?: boolean }
|
||||
|
||||
/** MITHOME-123: internal JSON paths become page links, the rest stay URLs. */
|
||||
function toCtaLink({ text, href, external }: CtaJson) {
|
||||
const page = internalPathToPageKey(href)
|
||||
return page
|
||||
? { text, linkType: 'page' as const, page, external }
|
||||
: { text, linkType: 'url' as const, href, external }
|
||||
}
|
||||
|
||||
function buildHomeData(json: typeof homeJson) {
|
||||
const { hero, about, services, cta, serviceFeatures } = json
|
||||
return {
|
||||
hero: {
|
||||
...hero,
|
||||
trustBullets: toStringArray(hero.trustBullets),
|
||||
cta: { primary: toCtaLink(hero.cta.primary), secondary: toCtaLink(hero.cta.secondary) },
|
||||
},
|
||||
about,
|
||||
services: {
|
||||
|
||||
Reference in New Issue
Block a user