init commit for iPAL-kit plugin
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/** Which part comes first in a composed title. */
|
||||
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
|
||||
/** Separator between page title and site name. Defaults to ' | '. */
|
||||
separator?: string
|
||||
/** Site name, e.g. 'Acme Inc'. */
|
||||
siteName?: null | string
|
||||
}
|
||||
|
||||
/**
|
||||
* 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({
|
||||
order = 'page-first',
|
||||
pageTitle,
|
||||
separator = ' | ',
|
||||
siteName,
|
||||
}: ComposeTitleArgs): string {
|
||||
const page = pageTitle?.trim()
|
||||
const site = siteName?.trim()
|
||||
|
||||
if (page && site) {
|
||||
return order === 'site-first' ? `${site}${separator}${page}` : `${page}${separator}${site}`
|
||||
}
|
||||
return page || site || ''
|
||||
}
|
||||
Reference in New Issue
Block a user