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>
53 lines
2.1 KiB
TypeScript
53 lines
2.1 KiB
TypeScript
/**
|
|
* MITHOME-111: a Global mezők utólagos `localized: true` jelölése után a
|
|
* meglévő (nem lokalizált alakú) értékeket `{ hu: érték }` alakba csomagolja.
|
|
*
|
|
* WHY nem a JSON-seed újrafuttatása (mint MITHOME-110-nél): az felülírná az
|
|
* ügyfél admin-szerkesztéseit. Ez a migráció a tárolt értéket őrzi meg —
|
|
* a publikált dokumentumon ÉS a draft/verzió rekordokon is.
|
|
*
|
|
* Az írás módja (közvetlen Mongo, hookok/új verzió nélkül): lásd
|
|
* src/lib/migrate-global-docs.ts.
|
|
*
|
|
* Futás: productionben induláskor automatikusan (`prodMigrations`,
|
|
* payload.config.ts); dev-ben `npx payload migrate`. Idempotens.
|
|
*/
|
|
import type { MigrateDownArgs, MigrateUpArgs } from '@payloadcms/db-mongodb'
|
|
import type { GlobalConfig } from 'payload'
|
|
|
|
import { Home } from '../globals/Home'
|
|
import { About } from '../globals/About'
|
|
import { Services } from '../globals/Services'
|
|
import { Contact } from '../globals/Contact'
|
|
import { Common } from '../globals/Common'
|
|
import {
|
|
collectLocalizedPaths,
|
|
topLevelKeys,
|
|
unwrapLocalized,
|
|
wrapLocalized,
|
|
type LocalizedPath,
|
|
} from '../lib/localize-paths'
|
|
import { rewriteGlobalDocs } from '../lib/migrate-global-docs'
|
|
|
|
const LOCALIZED_GLOBALS: readonly GlobalConfig[] = [Home, About, Services, Contact, Common]
|
|
|
|
type Transform = (doc: Record<string, unknown>, paths: readonly LocalizedPath[]) => number
|
|
type Args = MigrateUpArgs | MigrateDownArgs
|
|
|
|
async function migrateAll(args: Args, transform: Transform) {
|
|
for (const global of LOCALIZED_GLOBALS) {
|
|
const paths = collectLocalizedPaths(global.fields as never)
|
|
const changed = await rewriteGlobalDocs(args, global.slug, topLevelKeys(paths), (data) => transform(data, paths))
|
|
args.payload.logger.info(`MITHOME-111 locale migration: ${global.slug} — ${changed} value(s) rewritten`)
|
|
}
|
|
}
|
|
|
|
export async function up(args: MigrateUpArgs): Promise<void> {
|
|
await migrateAll(args, (doc, paths) => wrapLocalized(doc, paths))
|
|
}
|
|
|
|
/** TRADEOFF: drops every non-hu value — restore from a DB dump instead if possible. */
|
|
export async function down(args: MigrateDownArgs): Promise<void> {
|
|
await migrateAll(args, (doc, paths) => unwrapLocalized(doc, paths))
|
|
}
|