Project-defined link styles, legal links from System Pages; audit catches content-keyed logic, Polish text in code, link fields in globals
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -75,3 +75,31 @@ export function homeSlugFrom(settings: unknown, field = 'homepage'): string | un
|
||||
const slug = home && typeof home === 'object' ? (home as { slug?: unknown }).slug : undefined
|
||||
return typeof slug === 'string' && slug ? slug : undefined
|
||||
}
|
||||
|
||||
export type SystemLink = { role: string } & ResolvedLink
|
||||
|
||||
/**
|
||||
* Links to the pages assigned in Site Settings → System Pages (privacy policy,
|
||||
* cookie policy, terms…) — href AND label from the panel: the label is the
|
||||
* page's own title in this locale, so nothing is typed in code and a renamed
|
||||
* or translated page updates the footer by itself. Unassigned roles are skipped.
|
||||
*
|
||||
* resolveSystemLinks(settings, { locale, config, homeSlug }) // privacy, cookies, terms
|
||||
* resolveSystemLinks(settings, { …, roles: ['termsOfService'] })
|
||||
*
|
||||
* `settings` = SiteSettings read with depth ≥ 1 (lib/content getSettings is depth 2).
|
||||
*/
|
||||
export function resolveSystemLinks(
|
||||
settings: unknown,
|
||||
{ roles = ['privacyPolicy', 'cookiePolicy', 'termsOfService'], ...options }: { roles?: readonly string[] } & ResolveLinkHrefOptions,
|
||||
): SystemLink[] {
|
||||
if (!settings || typeof settings !== 'object') {return []}
|
||||
const record = settings as Record<string, unknown>
|
||||
return roles.flatMap((role) => {
|
||||
const page = record[role]
|
||||
if (!page || typeof page !== 'object') {return []}
|
||||
const title = (page as { title?: unknown }).title
|
||||
const link = resolveLink({ type: 'internal', label: typeof title === 'string' ? title : '', page }, options)
|
||||
return link && link.label ? [{ ...link, role }] : []
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user