Files
ipal-kit/dist/modules/seo/composeTitle.js
T

28 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** Which part comes first in a composed title. */ /**
* Composes a full document title from a page title and the site name.
*
* - both, page-first: "About Us | Acme Inc"
* - both, site-first: "Acme Inc | About Us"
* - page only: "About Us"
* - site only: "Acme Inc"
* - neither: ""
*
* Pure function — no dependency on Payload or request state.
*/ export function composeTitle({ pageTitle, siteName, separator = ' | ', order = 'page-first' }) {
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 || '';
}
//# sourceMappingURL=composeTitle.js.map