Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67e8da6ec3 | ||
|
|
191cf44361 | ||
|
|
6a0fefdbae | ||
|
|
0069b28941 | ||
|
|
3da9d6b1d0 | ||
|
|
eb52253dc4 |
@@ -8,6 +8,39 @@ wersji naraz przejdź po kolei wszystkie sekcje „Wymaga zmian w projekcie” o
|
||||
wersji, którą masz. Nowe wydanie = nowa sekcja na górze; najstarsze usuwamy
|
||||
dopiero powyżej 20.
|
||||
|
||||
## 1.9.4
|
||||
|
||||
### Nowe
|
||||
- **Style linków z projektu:** `buildLinkField` / `buildLinksField({ appearances })` przyjmują dowolne nazwy
|
||||
i etykiety panelu — `['primary', { label: 'Highlighted', value: 'highlight' }]`. Wcześniej tylko
|
||||
primary / secondary / link, co pchało projekty do warunków po treści (`label === 'Tesla'`).
|
||||
- **Linki prawne:** `getSystemLinks(locale, roles?)` w `lib/content` (i `resolveSystemLinks`) — href i
|
||||
etykieta (tytuł strony w danym języku) z Site Settings → System Pages.
|
||||
|
||||
### Audyt
|
||||
- ERROR: logika po treści (`label?.toLowerCase() === '…'`), polski tekst w literałach kodu frontu,
|
||||
pola linków/przycisków w globalach (`prefooterButtonUrl`, `ctaLabel`…); WARNING: relacja do `pages` w
|
||||
globalu zamiast `buildLinkField`.
|
||||
|
||||
### Wymaga zmian w projekcie
|
||||
- Globale Header/Footer z polami `page` + `url` + `label` → `buildLinkField` (dane trzeba przenieść —
|
||||
skill **ipal-migrate-fields**), potem `resolveNav` / `resolveLink`; linki prawne → `getSystemLinks`.
|
||||
|
||||
## 1.9.3
|
||||
|
||||
### Audyt
|
||||
- `ipal-audit` łapie ręczne liczenie linków pod dowolną nazwą (`resolveHref`, `getHref`…):
|
||||
slug strony głównej wpisany w kodzie (`=== 'home'`, `'strona-glowna'`) i URL sklejany ze sluga
|
||||
(`` `/${slug}` ``, `'/' + slug`) — ERROR z odesłaniem do `resolveLink` / `resolveNav`. Taka kopia gubi
|
||||
prefiks języka, stronę główną z Site Settings, filtr `javascript:` i martwe linki.
|
||||
- Poprawka: komentarz zaczynający linię nie jest już zgłaszany przez reguły ignorujące komentarze
|
||||
(mniej fałszywych alarmów).
|
||||
- AGENT.md (zakazane zamienniki) i links.md: jak przemapować pole `page` + `url` na `resolveLink`.
|
||||
|
||||
### Wymaga zmian w projekcie
|
||||
- Nowe ERROR-y w audycie wskazują własne funkcje linków — zamień na `resolveLink(link, locale)` z `lib/content`
|
||||
(PROGRAMISTA §6 poz. 33).
|
||||
|
||||
## 1.9.2
|
||||
|
||||
Import zamiast kodu: to, co każdy projekt pisał tak samo, jest w pluginie — logika i
|
||||
|
||||
+7
-2
@@ -66,7 +66,7 @@ strona), **P** = test w panelu. Pełny kod: PROGRAMISTA.md §2.
|
||||
| 12 | Zgoda + analityka | `<SiteProviders logEndpoint="/api/ipal/consent" banner={<CookieBanner equalChoice />}>` (ConsentProvider, baner, CookieButton, Analytics w dobrej kolejności); ID narzędzi w panelu; lista ciasteczek ze skanu (cookie-scan → import) + `<CookieTable>` na stronie polityki cookies | consent.md, analytics.md | A, `ipal-consent-check` |
|
||||
| 13 | Bezpieczeństwo | `buildSecurityHeaders` w `next.config.ts`; `twoFactor: { issuer, plugin: payloadTotp }`; CSP `report-only` → `enforce`; `IPAL_IP_HEADER` na produkcji | security.md, forms.md | A |
|
||||
| 14 | Operacje | `src/app/api/health/route.ts` (`healthRoute`); `src/instrumentation.ts` z `assertEnv(ipalEnvRules({ storage: true, ipHeader: true }))`; staging z `IPAL_NOINDEX=1`; testy smoke (§8a) | `healthRoute`, `assertEnv`, `ipalEnvRules` | A |
|
||||
| 15 | Strony systemowe | Site Settings → System Pages: homepage, 404, polityka prywatności, cookies; linki prawne w stopce przez rolę | `getSystemPagePath`, `getNotFoundPage` | P |
|
||||
| 15 | Strony systemowe | Site Settings → System Pages: homepage, 404, polityka prywatności, cookies; linki prawne w stopce przez rolę (`getSystemLinks(locale)`) | `getSystemLinks`, `getSystemPagePath`, `getNotFoundPage` | P |
|
||||
| 16 | **Zero hardkodów** | każdy tekst, link, obraz, plik, dane firmy z panelu; domeny i klucze z `.env` (§2) | — | A, P |
|
||||
| 17 | **Treść** | jedno h1, odpowiedź na początku sekcji, fakty, linki wewnętrzne, FAQ z prawdziwych pytań, `aiSummary`, sameAs, spójne dane firmy (§0c) | — | S, P |
|
||||
| 18 | **Skalowanie** | `fluid.css` / `fluid-wide.css`, hero na `--ipal-hero-min-h`, lista ekranów §6.11a (w tym 1366×768) | — | A, przeglądarka |
|
||||
@@ -89,6 +89,8 @@ Nie warunkujesz providera ani widgetu w kodzie — wpinasz zawsze.
|
||||
| ręczny `<script type="application/ld+json">` | brak escapowania, rozjazd z panelem | `JsonLdGraph` |
|
||||
| własny `sitemap.ts` / tekstowy `robots.txt` w `public/` | bez hreflang, noindex i stron systemowych | `sitemapRoute`, `robots` z `lib/content` |
|
||||
| własny `llms.txt` w `public/` | statyczny, starzeje się | `createLlmsTxtRoute` |
|
||||
| własna funkcja linku (`resolveHref`, `getHref`…): slug strony głównej w kodzie (`=== 'home'`), `` `/${slug}` `` | brak prefiksu języka, strona główna zależy od Site Settings, `javascript:` z panelu w `href`, martwy link prowadzi na `/` | `resolveLink(link, locale)` / `resolveNav` z `lib/content` (pole: `buildLinkField`) |
|
||||
| pola `page` + `url` + `label` w globalach, `prefooterButtonUrl`, `ctaLabel`; styl po treści (`label === 'Tesla'`); etykiety linków prawnych w kodzie | redaktor nie wybierze pliku / nowej karty / stylu; zmiana nazwy psuje wygląd; tekst PL w wersji EN | `buildLinkField` / `buildLinksField` z `appearances`, `resolveNav`, `getSystemLinks` |
|
||||
| `@aws-sdk/client-s3` / własny upload do bucketa | omija hooki mediów i URL z `R2_PUBLIC_URL` | `buildR2Storage` |
|
||||
|
||||
### Świadomy wyjątek (tylko z decyzji klienta)
|
||||
@@ -646,7 +648,8 @@ Skill: **ipal-nav**.
|
||||
zbudowane z `buildLinkField` — model danych firmy zależy od kraju (NIP/ABN/EIN).
|
||||
- Menu: jeden poziom podmenu, nie głębiej. CTA w nagłówku = `links`.
|
||||
- Logo i nazwa z Site Settings — nie duplikuj pól w Header.
|
||||
- **Linki prawne w stopce** z ról System Pages (`getSystemPagePath`), nie ręcznie.
|
||||
- **Linki prawne w stopce** z ról System Pages: `await getSystemLinks(locale)` (href + tytuł strony), nie ręcznie i bez etykiet w kodzie.
|
||||
- Wyróżnienie pozycji menu / wariant przycisku = `appearance` z panelu (`buildLinkField({ appearances: [...] })`, dowolne nazwy), nigdy warunek na treści (`label === '…'`).
|
||||
- Linki rozwiązuj **na serwerze**: `await resolveNav(header.navItems, locale)` z `lib/content`
|
||||
→ `{ href, label, internal, newTab, targetProps, children }[]` (martwe linki pominięte); do
|
||||
komponentu klienckiego (MobileNav) idą tylko te dane — `CMSLink` jest serwerowy.
|
||||
@@ -790,6 +793,8 @@ projekcie → **ipal-plugin-gap**, nie kopia.
|
||||
|---|---|---|
|
||||
| href + nowa karta + rel + internal dla linku z panelu | `resolveLink(link, locale)` (`lib/content`) / `resolveLink(link, opts)` | links.md |
|
||||
| Menu z globala (dowolna głębokość, martwe linki pominięte) | `resolveNav(items, locale)` | links.md |
|
||||
| Linki prawne w stopce (href + tytuł strony) | `getSystemLinks(locale)` / `resolveSystemLinks` | links.md |
|
||||
| Wyróżniona pozycja, wariant przycisku | `buildLinkField({ appearances: [...] })` — nazwy projektu | links.md |
|
||||
| Ścieżki językowe, przełącznik, hreflang | `getLocalizedSlugs`, `switchLocalePath`, `LanguageSwitcher`, `buildLocalizedPath` | i18n.md |
|
||||
| Bezpieczny URL (bez `javascript:`) | `safeHref` | links.md |
|
||||
|
||||
|
||||
@@ -41,7 +41,8 @@ report() {
|
||||
|
||||
g() { grep -rnE "$@" 2>/dev/null || true; }
|
||||
# drop matches that sit inside a // or /* comment (keeps http:// URLs)
|
||||
nc() { grep -vE "(^|[^:])//.*$1|/\*.*$1" || true; }
|
||||
# (also a whole-line comment right after grep's "file:line:" prefix)
|
||||
nc() { grep -vE "^[^:]+:[0-9]+:[[:space:]]*(//|/?\*)|(^|[^:])//.*$1|/\*.*$1" || true; }
|
||||
dirs() { for d in "$@"; do [ -d "$d" ] && printf '%s ' "$d"; done; }
|
||||
|
||||
BLOCKS=$(dirs src/blocks)
|
||||
@@ -189,6 +190,28 @@ report WARNING "files that usually duplicate the plugin" "§3 plugin has resolve
|
||||
"$(ls src/lib/pages.ts src/lib/locales.ts 2>/dev/null)"
|
||||
report ERROR "project copy of link fields" "links.md — use buildLinkField / buildLinksField / resolveLinkHref from the plugin" \
|
||||
"$(ls src/fields/link.ts src/lib/links.ts 2>/dev/null; g "from '@/fields/link'|from '@/lib/links'" src --include=*.ts --include=*.tsx)"
|
||||
# Hand-rolled link resolution under another name (resolveHref, getHref…): the plugin knows the
|
||||
# homepage from Site Settings, adds the locale prefix, drops unsafe URLs and dead links.
|
||||
FRONT=$(dirs src/app src/blocks src/components src/lib src/globals src/collections)
|
||||
if [ -n "$FRONT" ]; then
|
||||
report ERROR "hardcoded homepage slug" "links.md — the homepage comes from Site Settings: resolveLink(link, locale) / getHomeSlug(locale), never a slug name in code" \
|
||||
"$(g "(===|!==|==|!=) *['\"](home|homepage|strona-glowna|glowna|start|index)['\"]|['\"](home|homepage|strona-glowna|glowna|start|index)['\"] *(===|!==|==|!=)" $FRONT --include=*.ts --include=*.tsx | grep -v '/(payload)/' | grep -vE "[Tt]ype *[!=]==? *['\"]home|['\"]home['\"] *[!=]==? *[A-Za-z_.]*[Tt]ype" | nc '=')"
|
||||
report ERROR "URL built from a slug by hand" "links.md — resolveLink / resolveNav (lib/content) or buildLocalizedPath: locale prefix, homepage, unsafe and dead links" \
|
||||
"$(g '`/\$\{[^}]*[Ss]lug|['"'"'"]/['"'"'"] *\+ *[A-Za-z_.?]*[Ss]lug' $FRONT --include=*.ts --include=*.tsx | grep -v '/(payload)/' | nc '[Ss]lug')"
|
||||
fi
|
||||
if [ -n "$FRONT" ]; then
|
||||
report ERROR "logic keyed on content text" "§2 the editor can rename it any time — a style/flag is a panel field (e.g. buildLinkField({ appearances: [...] }))" \
|
||||
"$(g "\.(label|title|heading|name|text)\??\.(toLowerCase|toUpperCase|trim)\(\) *[!=]==? *['\"]|\.(label|title|heading)\?? *[!=]==? *['\"][^'\"]+['\"]" $FRONT --include=*.ts --include=*.tsx | grep -v '/(payload)/' | nc '==')"
|
||||
report ERROR "hardcoded Polish text in code" "§2 every visible text comes from the panel — legal links: getSystemLinks(locale) (page titles), labels: localized fields" \
|
||||
"$(g "['\"\`][^'\"\`]*[ąćęłńóśźżĄĆĘŁŃÓŚŹŻ][^'\"\`]*['\"\`]" $FRONT --include=*.ts --include=*.tsx | grep -v '/(payload)/' | nc '[ąćęłńóśźżĄĆĘŁŃÓŚŹŻ]')"
|
||||
fi
|
||||
GLOBALS=$(dirs src/globals)
|
||||
if [ -n "$GLOBALS" ]; then
|
||||
report ERROR "link/button fields in globals" "§6.5 Header/Footer links and buttons = buildLinkField / buildLinksField (page, URL or file + label + style), never ctaLabel/buttonUrl/…Url" \
|
||||
"$(g "name: *'[a-zA-Z]*([cC]ta|[bB]utton|Url|Href|[pP]df)[a-zA-Z]*'" $GLOBALS --include=*.ts)"
|
||||
report WARNING "page relationship in a global" "links.md — a link to a page is buildLinkField (it also handles URL, file, new tab, style); then resolveNav / resolveLink" \
|
||||
"$(g "relationTo: *'pages'" $GLOBALS --include=*.ts)"
|
||||
fi
|
||||
report ERROR "manual Lexical rendering" "§7 use RenderRichText" \
|
||||
"$(g 'node\.type *===' src --include=*.tsx | nc 'node')"
|
||||
HTML=$(node "$(dirname "$0")/html-check.mjs" src)
|
||||
|
||||
@@ -24,7 +24,7 @@ Wymaga prymitywów z `../ipal-block/resources/kod-sekcji.md` (jak skill ipal-blo
|
||||
Nie twórz `lib/navigation.ts`.
|
||||
4. `src/components/layout/Header.tsx`, `Footer.tsx` (serwer), `MobileNav.tsx`
|
||||
(`'use client'`, tylko stan otwarcia, dane przez props, `import type { NavItem } from '@intecion/ipal-kit'`).
|
||||
5. **Linki prawne w stopce** z ról System Pages (`getSystemPagePath` + tytuł
|
||||
5. **Linki prawne w stopce** z ról System Pages: `getSystemLinks(locale)` (href + tytuł
|
||||
strony) — nie jako ręczne pozycje. Rok w copyright z kodu, nazwa z `Company`.
|
||||
6. Logo z Site Settings przez `<Media>` — nie duplikuj pola w Header.
|
||||
7. Podepnij w `src/app/(frontend)/[locale]/layout.tsx` (pobranie globali przez
|
||||
|
||||
@@ -78,8 +78,10 @@ export const Footer: GlobalConfig = {
|
||||
}
|
||||
```
|
||||
|
||||
- **Linki prawne w stopce** (polityka, cookies, regulamin) renderuj z ról System
|
||||
Pages (`getSystemPagePath` + tytuł strony) — nie dodawaj ich ręcznie do `columns`.
|
||||
- **Linki prawne w stopce** (polityka, cookies, regulamin): `await getSystemLinks(locale)` z `lib/content`
|
||||
— href i etykieta (tytuł strony) z System Pages; nie dodawaj ich ręcznie do `columns`, nie wpisuj etykiet w kod.
|
||||
- Wyróżniona pozycja menu / przycisk w innym kolorze = styl w panelu:
|
||||
`buildLinkField({ appearances: ['default', { label: 'Highlighted', value: 'highlight' }] })` → klasa w projekcie.
|
||||
- **Dane firmy** (nazwa, adres, NIP/ABN, telefon) — global `company` projektu;
|
||||
stopka i JSON-LD czytają z niego. Rok w copyright licz w kodzie
|
||||
(`new Date().getFullYear()`), nazwę bierz z globala.
|
||||
|
||||
@@ -219,7 +219,7 @@ export const {
|
||||
getCachedPayload, getSettings, getConfiguredLocales, resolveRoute, getEntries, getNotFoundPage,
|
||||
generatePageMetadata, generateStaticParams, getPageJsonLd, resolvePageRedirect, i18n,
|
||||
// layout, formularze, linki
|
||||
getSiteShell, getFormTexts, getLinkOptions, getHomeSlug, resolveLink, resolveNav,
|
||||
getSiteShell, getFormTexts, getLinkOptions, getHomeSlug, resolveLink, resolveNav, getSystemLinks,
|
||||
// trasy (re-eksport w app/)
|
||||
sitemap, sitemapRoute, robots, manifest, llmsRoute, llmsFullRoute, markdownRoute,
|
||||
mcpGET, mcpPOST, healthRoute, indexNowKeyRoute,
|
||||
|
||||
+21
-1
@@ -22,7 +22,7 @@ fields: [
|
||||
| `name` | `'link'` / `'links'` | nazwa pola |
|
||||
| `relationTo` | `'pages'` | kolekcja dla typu „Page” |
|
||||
| `uploadTo` | `'media'` | kolekcja dla typu „File” (PDF, dokumenty) |
|
||||
| `appearances` | `['primary','secondary','link']` | style do wyboru; `false` = bez pola |
|
||||
| `appearances` | `['primary','secondary','link']` | style do wyboru — **dowolne nazwy projektu**, np. `['primary', { label: 'Highlighted', value: 'highlight' }]` (menu z wyróżnioną pozycją, przycisk w kolorze marki); `false` = bez pola |
|
||||
| `disableLabel` | `false` | bez etykiety (link owija kartę / obraz) — tylko `buildLinkField` |
|
||||
| `required` | `false` | wymagane pola celu i etykiety |
|
||||
| `maxRows` | `2` | tylko `buildLinksField` |
|
||||
@@ -102,6 +102,26 @@ export async function CMSLink({ link, locale, className, children }: { link: Cms
|
||||
}
|
||||
```
|
||||
|
||||
**Nie pisz własnej wersji** (`resolveHref`, `getHref`, `` `/${slug}` ``, `slug === 'home'`): gubi prefiks
|
||||
języka, stronę główną z Site Settings, filtr `javascript:` i martwe linki. `ipal-audit` zgłasza to jako
|
||||
ERROR. Pole w innym kształcie (np. `page` + `url`) mapujesz na kształt pluginu zamiast liczyć href:
|
||||
`resolveLink(url?.trim() ? { type: 'external', url } : { type: 'internal', page }, locale)`.
|
||||
|
||||
Wyróżnienie, kolor, wariant pozycji = **styl z panelu** (`appearances`), mapowany na klasy w projekcie
|
||||
(`l.appearance === 'highlight'` → klasa). Nigdy logika po treści (`label === 'Tesla'`) — redaktor zmieni
|
||||
nazwę i styl zniknie; `ipal-audit` zgłasza to jako ERROR.
|
||||
|
||||
## Linki prawne — `getSystemLinks`
|
||||
|
||||
```ts
|
||||
const legal = await getSystemLinks(locale) // z lib/content
|
||||
// [{ role: 'privacyPolicy', href: '/pl/polityka-prywatnosci', label: 'Polityka prywatności', internal, targetProps }, …]
|
||||
await getSystemLinks(locale, ['privacyPolicy', 'termsOfService']) // wybrane role
|
||||
// bez lib/content: resolveSystemLinks(settings, { locale, config: i18nConfig, homeSlug, roles })
|
||||
```
|
||||
Strony przypisane w Site Settings → System Pages; **etykieta to tytuł strony** w danym języku, więc w kodzie
|
||||
nie ma tekstów („Polityka prywatności” na sztywno psuje wersję EN). Nieprzypisana rola → pominięta.
|
||||
|
||||
## Menu — `resolveNav`
|
||||
|
||||
```ts
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@intecion/ipal-kit",
|
||||
"version": "1.9.2",
|
||||
"version": "1.9.4",
|
||||
"description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
|
||||
+3
-1
@@ -132,16 +132,18 @@ export { createProxy, DEFAULT_PROXY_MATCHER } from './modules/i18n/index.js'
|
||||
export { resolveLocalized } from './modules/i18n/index.js'
|
||||
export { buildIntegrationStatusBanner, buildIntegrationStatusField, recordIntegrationStatus } from './modules/integrations/index.js'
|
||||
export type { IntegrationState, IntegrationStatus } from './modules/integrations/index.js'
|
||||
export { buildLinkField, buildLinksField, homeSlugFrom, resolveLink, resolveLinkHref, resolveNav, safeHref } from './modules/links/index.js'
|
||||
export { buildLinkField, buildLinksField, homeSlugFrom, resolveLink, resolveLinkHref, resolveNav, resolveSystemLinks, safeHref } from './modules/links/index.js'
|
||||
export type {
|
||||
BuildLinkFieldOptions,
|
||||
BuildLinksFieldOptions,
|
||||
LinkAppearance,
|
||||
LinkAppearanceOption,
|
||||
LinkValue,
|
||||
NavItem,
|
||||
ResolvedLink,
|
||||
ResolveLinkHrefOptions,
|
||||
ResolveNavOptions,
|
||||
SystemLink,
|
||||
} from './modules/links/index.js'
|
||||
// Read-only MCP server (Claude/agents connect to the site and query it).
|
||||
export { createMcpRoute } from './modules/mcp/index.js'
|
||||
|
||||
@@ -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 }] : []
|
||||
})
|
||||
}
|
||||
|
||||
@@ -76,3 +76,31 @@ describe('section fields', () => {
|
||||
expect(buildSectionSettingsField({ backgrounds: false }).fields.map((f) => ('name' in f ? f.name : ''))).toEqual(['anchor'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('project-defined link styles', () => {
|
||||
test('appearances accept the project\'s own names and panel labels', async () => {
|
||||
const { buildLinkField } = await import('../src/modules/links/buildLinkField.js')
|
||||
const field = buildLinkField({ appearances: ['primary', { label: 'Highlighted', value: 'highlight' }] })
|
||||
const select = field.fields.find((f) => 'name' in f && f.name === 'appearance') as { defaultValue: string; options: unknown[] }
|
||||
expect(select.options).toEqual([{ label: 'primary', value: 'primary' }, { label: 'Highlighted', value: 'highlight' }])
|
||||
expect(select.defaultValue).toBe('primary')
|
||||
expect(resolveLink({ ...page('oferta'), appearance: 'highlight' }, opts)?.appearance).toBe('highlight')
|
||||
})
|
||||
})
|
||||
|
||||
describe('resolveSystemLinks', () => {
|
||||
test('href and label (page title) from System Pages; unassigned roles skipped', async () => {
|
||||
const { resolveSystemLinks } = await import('../src/modules/links/resolveNav.js')
|
||||
const settings = {
|
||||
cookiePolicy: null,
|
||||
privacyPolicy: { slug: 'polityka-prywatnosci', title: 'Polityka prywatności' },
|
||||
termsOfService: { slug: 'regulamin', title: 'Regulamin' },
|
||||
}
|
||||
expect(resolveSystemLinks(settings, opts).map((l) => [l.role, l.href, l.label])).toEqual([
|
||||
['privacyPolicy', '/pl/polityka-prywatnosci', 'Polityka prywatności'],
|
||||
['termsOfService', '/pl/regulamin', 'Regulamin'],
|
||||
])
|
||||
expect(resolveSystemLinks(settings, { ...opts, roles: ['termsOfService'] })).toHaveLength(1)
|
||||
expect(resolveSystemLinks(null, opts)).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user