Files
ipal-kit/dist/modules/pages/getSystemPagePath.js
T
2026-07-31 23:21:51 +02:00

36 lines
1.3 KiB
JavaScript

import { buildLocalizedPath, getLocalizedSlugs } from '../i18n/index.js';
/**
* Resolves a system-page assignment to a locale-aware path.
*
* Bridges the Pages module (which document plays a role) and the i18n module
* (how that document's localized slug becomes a URL). This is what powers
* "visit /pl → serve the homepage": read SiteSettings.homepage, pass the
* related document here, get /pl/strona-glowna (or /pl if it's the home slug).
*
* Returns undefined when the role is unassigned or the assigned page has no
* slug in the target locale — the caller decides the fallback (e.g. 404,
* redirect to default locale).
*
* @example
* const settings = await payload.findGlobal({ slug: 'site-settings', locale: 'all', depth: 1 })
* getSystemPagePath({ page: settings.homepage, locale: 'pl', config })
* // → '/pl' (home slug collapses to root)
* getSystemPagePath({ page: settings.privacyPolicy, locale: 'en', config })
* // → '/en/privacy-policy'
*/ export function getSystemPagePath({ config, homeSlug = 'home', locale, page }) {
if (!page?.slug) {
return undefined;
}
const slugs = getLocalizedSlugs({
config,
slugField: page.slug
});
return buildLocalizedPath({
config,
homeSlug,
locale,
slugs
});
}
//# sourceMappingURL=getSystemPagePath.js.map