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:
2026-10-16 13:11:08 +02:00
co-authored by Claude Opus 5.5
parent 0069b28941
commit 6a0fefdbae
13 changed files with 144 additions and 17 deletions
+13 -4
View File
@@ -2,11 +2,19 @@ import type { ArrayField, Field, GroupField } from 'payload'
import { rowLabel } from '../admin-ui/rowLabel.js'
/** The default styles. A project may use any names of its own — see `appearances`. */
export type LinkAppearance = 'link' | 'primary' | 'secondary'
/** One style the editor may pick: a value (`'highlight'`) or `{ label, value }` for a friendlier panel label. */
export type LinkAppearanceOption = { label: string; value: string } | string
export type BuildLinkFieldOptions = {
/** Visual styles the editor may pick. `false` → no appearance select. Default all three. */
appearances?: false | LinkAppearance[]
/**
* Visual styles the editor may pick — the project's own names, mapped to its
* classes in Button.tsx / the menu: `['primary', 'secondary', { label: 'Highlighted', value: 'highlight' }]`.
* `false` → no appearance select. Default primary / secondary / link.
*/
appearances?: false | readonly LinkAppearanceOption[]
/** Hide the label — for links that wrap something (a whole card, an image). */
disableLabel?: boolean
/** Field name. Default 'link'. */
@@ -100,11 +108,12 @@ export function buildLinkField({
}
if (appearances && appearances.length) {
const options = appearances.map((a) => (typeof a === 'string' ? { label: a, value: a } : a))
fields.push({
name: 'appearance',
type: 'select',
defaultValue: appearances[0],
options: appearances.map((a) => ({ label: a, value: a })),
defaultValue: options[0].value,
options,
})
}
+3 -3
View File
@@ -1,6 +1,6 @@
export { buildLinkField, buildLinksField } from './buildLinkField.js'
export type { BuildLinkFieldOptions, BuildLinksFieldOptions, LinkAppearance } from './buildLinkField.js'
export type { BuildLinkFieldOptions, BuildLinksFieldOptions, LinkAppearance, LinkAppearanceOption } from './buildLinkField.js'
export { resolveLinkHref, safeHref } from './resolveLinkHref.js'
export type { LinkValue, ResolveLinkHrefOptions } from './resolveLinkHref.js'
export { homeSlugFrom, resolveLink, resolveNav } from './resolveNav.js'
export type { NavItem, ResolvedLink, ResolveNavOptions } from './resolveNav.js'
export { homeSlugFrom, resolveLink, resolveNav, resolveSystemLinks } from './resolveNav.js'
export type { NavItem, ResolvedLink, ResolveNavOptions, SystemLink } from './resolveNav.js'
+28
View File
@@ -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 }] : []
})
}