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:
@@ -7,7 +7,7 @@ import type { AnalyticsConfig } from '../analytics/types.js'
|
||||
import type { ConsentTexts } from '../consent/texts.js'
|
||||
import type { ArchiveEntries, ContentOption, ResolvedRoute } from '../content/index.js'
|
||||
import type { I18nConfig } from '../i18n/index.js'
|
||||
import type { LinkValue, NavItem, ResolvedLink, ResolveLinkHrefOptions } from '../links/index.js'
|
||||
import type { LinkValue, NavItem, ResolvedLink, ResolveLinkHrefOptions, SystemLink } from '../links/index.js'
|
||||
import type { CreateMcpRouteArgs } from '../mcp/createMcpRoute.js'
|
||||
import type { FormNotificationTexts } from '../notifications/types.js'
|
||||
import type { PageMetadata, RobotsOptions, RobotsRules, SitemapEntry, SitemapStyleOptions } from '../seo/index.js'
|
||||
@@ -19,7 +19,7 @@ import { getArchiveEntries, resolveRoute as resolveRouteRaw } from '../content/i
|
||||
import { MARKDOWN_PREFIX, markdownHref } from '../content/markdownNegotiation.js'
|
||||
import { resolveRedirect as resolveRedirectRaw } from '../content/resolveRedirect.js'
|
||||
import { createHealthRoute } from '../health/createHealthRoute.js'
|
||||
import { homeSlugFrom, resolveLink as resolveLinkRaw, resolveNav as resolveNavRaw } from '../links/resolveNav.js'
|
||||
import { homeSlugFrom, resolveLink as resolveLinkRaw, resolveNav as resolveNavRaw, resolveSystemLinks } from '../links/resolveNav.js'
|
||||
import { createMcpRoute } from '../mcp/createMcpRoute.js'
|
||||
import { getNotificationTexts } from '../notifications/getNotificationTexts.js'
|
||||
import { buildOrganizationJsonLd, sameAsUrls } from '../seo/buildOrganizationJsonLd.js'
|
||||
@@ -586,6 +586,13 @@ export function createContentHelpers({
|
||||
const resolveNav = async (items: unknown, locale: string, options: { childrenField?: string; linkField?: string } = {}): Promise<NavItem[]> =>
|
||||
resolveNavRaw(items, { ...(await getLinkOptions(locale)), ...options })
|
||||
|
||||
/**
|
||||
* Legal links for the footer from Site Settings → System Pages — href and label
|
||||
* (the page title) in this locale. Default roles: privacy policy, cookie policy, terms.
|
||||
*/
|
||||
const getSystemLinks = async (locale: string, roles?: readonly string[]): Promise<SystemLink[]> =>
|
||||
resolveSystemLinks(await getSettings(locale), { ...(await getLinkOptions(locale)), ...(roles ? { roles } : {}) })
|
||||
|
||||
/** Old slug → its new URL (308), for the catch-all page before notFound(). */
|
||||
const resolvePageRedirect = async (locale: string, segments: string[] | undefined): Promise<null | string> =>
|
||||
resolveRedirectRaw({
|
||||
@@ -683,6 +690,7 @@ export function createContentHelpers({
|
||||
getPageJsonLd,
|
||||
getSettings,
|
||||
getSiteShell,
|
||||
getSystemLinks,
|
||||
healthRoute,
|
||||
i18n,
|
||||
indexNowKeyRoute,
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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