Fixed support for multi-langual slugs
This commit is contained in:
@@ -2,14 +2,14 @@
|
||||
export type TitleOrder = 'page-first' | 'site-first'
|
||||
|
||||
type ComposeTitleArgs = {
|
||||
/** Defaults to 'page-first' — the page title is what a visitor scans for. */
|
||||
order?: TitleOrder
|
||||
/** Page-specific title, e.g. 'About Us'. */
|
||||
pageTitle?: null | string
|
||||
pageTitle?: string | null
|
||||
/** Site name, e.g. 'Acme Inc'. */
|
||||
siteName?: string | null
|
||||
/** Separator between page title and site name. Defaults to ' | '. */
|
||||
separator?: string
|
||||
/** Site name, e.g. 'Acme Inc'. */
|
||||
siteName?: null | string
|
||||
/** Defaults to 'page-first' — the page title is what a visitor scans for. */
|
||||
order?: TitleOrder
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,15 +24,23 @@ type ComposeTitleArgs = {
|
||||
* Pure function — no dependency on Payload or request state.
|
||||
*/
|
||||
export function composeTitle({
|
||||
order = 'page-first',
|
||||
pageTitle,
|
||||
separator = ' | ',
|
||||
siteName,
|
||||
separator = ' | ',
|
||||
order = 'page-first',
|
||||
}: ComposeTitleArgs): string {
|
||||
const page = pageTitle?.trim()
|
||||
const site = siteName?.trim()
|
||||
|
||||
if (page && site) {
|
||||
// Dedup: if the page title already ends with the site name (an editor wrote
|
||||
// "Budowa auta – RCC" into meta.title), don't append it again → avoid
|
||||
// "Budowa auta – RCC – RCC". Match the site name at the end, with or without
|
||||
// the separator before it.
|
||||
const sep = separator.trim()
|
||||
if (page === site || page.endsWith(`${sep} ${site}`) || page.endsWith(` ${site}`)) {
|
||||
return page
|
||||
}
|
||||
return order === 'site-first' ? `${site}${separator}${page}` : `${page}${separator}${site}`
|
||||
}
|
||||
return page || site || ''
|
||||
|
||||
Reference in New Issue
Block a user