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:
Do Siki
2026-09-29 01:26:42 +02:00
co-authored by Claude Opus 5.5
parent 38d34fab4c
commit e8ff7adeb5
12 changed files with 460 additions and 65 deletions
+14 -1
View File
@@ -11,6 +11,7 @@
import { getPayload } from 'payload'
import config from '@payload-config'
import type { Locale } from './i18n'
import { resolveCtaHref, type CtaLink } from './cta-link'
let cached: ReturnType<typeof getPayload> | undefined
@@ -19,6 +20,11 @@ function payloadClient() {
return cached
}
/** MITHOME-123: internal CTA targets are stored as a page, resolved per locale. */
function withHref<T extends CtaLink>(link: T, locale: Locale): T & { href: string } {
return { ...link, href: resolveCtaHref(link, locale) }
}
function unwrap(items: readonly { value: string }[] | null | undefined): string[] {
return (items ?? []).map((item) => item.value)
}
@@ -33,7 +39,14 @@ export async function getHomeContent(locale: Locale) {
const home = await payload.findGlobal({ slug: 'home', locale })
return {
...home,
hero: { ...home.hero, trustBullets: unwrap(home.hero?.trustBullets) },
hero: {
...home.hero,
trustBullets: unwrap(home.hero?.trustBullets),
cta: {
primary: withHref(home.hero.cta.primary, locale),
secondary: withHref(home.hero.cta.secondary, locale),
},
},
services: {
...home.services,
items: (home.services?.items ?? []).map((item) => ({