The titleSeparator select stored '|', '–', '-', '·', '/'. Select values become GraphQL enum names; '|', '–', '·' are invalid and '-' and '/' collide on '_', so every project's /api/graphql answered 500 since 1.0.1 (admin/REST unaffected). - Values are now pipe/endash/hyphen/middot/slash (same labels); TITLE_SEPARATORS and titleSeparatorChar map them to the character; titles accept old characters and custom project values literally - Field afterRead/beforeChange turn an old stored character into its name - MongoDB: rewritten at start (migrateTitleSeparator); Postgres: titleSeparatorSql() for the generated migration (verified up/down/up against Postgres 16) - Test builds the full plugin GraphQL schema and fails on invalid or duplicate enum names; unit tests for the mapping, hooks, SQL and Mongo rewrite - CHANGELOG Unreleased (Fixed + upgrade step 5), seo.md, ipal-upgrade, api.md Co-Authored-By: Claude Opus 5.5 <[email protected]>
145 lines
5.3 KiB
TypeScript
145 lines
5.3 KiB
TypeScript
import type { Field } from 'payload'
|
||
|
||
import { validateFaviconField } from '../../../modules/seo/index.js'
|
||
import { titleSeparatorName } from '../../../modules/seo/titleSeparator.js'
|
||
|
||
/**
|
||
* General site identity fields.
|
||
* Consumed by SEO/OG (siteName, defaultShareImage) and frontend (logo).
|
||
*
|
||
* Order (admin-ux §7): what visitors see first (name, description, images),
|
||
* then the profiles list, then the title format options in one row. The row is
|
||
* presentation only — data stays flat.
|
||
*/
|
||
export const generalFields: Field[] = [
|
||
{
|
||
name: 'siteName',
|
||
type: 'text',
|
||
admin: {
|
||
description: {
|
||
en: 'Shown in page titles and when a link is shared.',
|
||
pl: 'Widoczna w tytułach stron i przy udostępnianiu linków.',
|
||
},
|
||
},
|
||
label: { en: 'Site name', pl: 'Nazwa witryny' },
|
||
localized: true,
|
||
required: true,
|
||
},
|
||
{
|
||
name: 'siteDescription',
|
||
type: 'textarea',
|
||
admin: {
|
||
description: {
|
||
en: 'Shown in search results for pages without their own description.',
|
||
pl: 'Widoczny w wynikach wyszukiwania stron bez własnego opisu.',
|
||
},
|
||
},
|
||
label: { en: 'Site description', pl: 'Opis witryny' },
|
||
localized: true,
|
||
},
|
||
{
|
||
name: 'logo',
|
||
type: 'upload',
|
||
label: { en: 'Logo', pl: 'Logo' },
|
||
relationTo: 'media',
|
||
},
|
||
{
|
||
name: 'favicon',
|
||
type: 'upload',
|
||
admin: {
|
||
// Warns under the field when the chosen icon is too small or not square (never blocks saving).
|
||
components: { afterInput: ['@intecion/ipal-kit/admin#FaviconCheck'] },
|
||
description: {
|
||
en: 'Square PNG or SVG, at least 48×48 px, shown in browser tabs and search results.',
|
||
pl: 'Kwadratowy plik PNG lub SVG, co najmniej 48×48 px, widoczny na kartach przeglądarki i w wynikach wyszukiwania.',
|
||
},
|
||
},
|
||
hooks: {
|
||
// Logs the same check on the server (the panel shows it through FaviconCheck).
|
||
beforeValidate: [validateFaviconField],
|
||
},
|
||
label: { en: 'Site icon (favicon)', pl: 'Ikona witryny (favicon)' },
|
||
relationTo: 'media',
|
||
},
|
||
{
|
||
name: 'defaultShareImage',
|
||
type: 'upload',
|
||
admin: {
|
||
description: {
|
||
en: 'Shown when a link to a page without its own image is shared.',
|
||
pl: 'Widoczny przy udostępnianiu linku do strony bez własnego obrazu.',
|
||
},
|
||
},
|
||
label: { en: 'Share image', pl: 'Obraz udostępniania' },
|
||
relationTo: 'media',
|
||
},
|
||
{
|
||
name: 'sameAs',
|
||
type: 'array',
|
||
admin: {
|
||
description: {
|
||
en: 'Your business on Google, LinkedIn, Facebook and similar, so search engines and AI assistants recognise you.',
|
||
pl: 'Profile firmy w Google, LinkedIn, Facebooku itp., dzięki którym wyszukiwarki i asystenci AI rozpoznają firmę.',
|
||
},
|
||
initCollapsed: true,
|
||
},
|
||
fields: [
|
||
{
|
||
name: 'url',
|
||
type: 'text',
|
||
admin: { placeholder: 'https://www.linkedin.com/company/acme' },
|
||
label: { en: 'Address (URL)', pl: 'Adres (URL)' },
|
||
required: true,
|
||
validate: (v: unknown, { req }: { req?: { i18n?: { language?: string } } } = {}) =>
|
||
(typeof v === 'string' && /^https?:\/\/\S+$/.test(v)) ||
|
||
(req?.i18n?.language === 'pl'
|
||
? 'Wpisz pełny adres, np. https://www.linkedin.com/company/acme'
|
||
: 'Enter a full address, e.g. https://www.linkedin.com/company/acme'),
|
||
},
|
||
],
|
||
label: { en: 'Official profiles', pl: 'Oficjalne profile' },
|
||
labels: { plural: { en: 'Profiles', pl: 'Profile' }, singular: { en: 'Profile', pl: 'Profil' } },
|
||
},
|
||
{
|
||
type: 'row',
|
||
fields: [
|
||
{
|
||
name: 'titleOrder',
|
||
type: 'select',
|
||
admin: {
|
||
description: {
|
||
en: 'Order of the page name and the site name in the browser tab.',
|
||
pl: 'Kolejność nazwy strony i nazwy witryny na karcie przeglądarki.',
|
||
},
|
||
},
|
||
defaultValue: 'page-first',
|
||
label: { en: 'Title order', pl: 'Kolejność w tytule' },
|
||
options: [
|
||
{ label: { en: 'Page first — About us | Acme', pl: 'Najpierw strona — O nas | Acme' }, value: 'page-first' },
|
||
{ label: { en: 'Site first — Acme | About us', pl: 'Najpierw witryna — Acme | O nas' }, value: 'site-first' },
|
||
],
|
||
},
|
||
{
|
||
name: 'titleSeparator',
|
||
type: 'select',
|
||
defaultValue: 'pipe',
|
||
// Values are GraphQL enum names (TITLE_SEPARATORS maps them to the character).
|
||
// Up to 1.14.4 the character itself was stored ('|') and broke /api/graphql;
|
||
// such a value still reads and saves as its name.
|
||
hooks: {
|
||
afterRead: [({ value }) => titleSeparatorName(value)],
|
||
beforeChange: [({ value }) => titleSeparatorName(value)],
|
||
},
|
||
label: { en: 'Title separator', pl: 'Separator w tytule' },
|
||
options: [
|
||
{ label: { en: 'Pipe — Page | Site', pl: 'Kreska pionowa — Strona | Witryna' }, value: 'pipe' },
|
||
{ label: { en: 'Dash — Page – Site', pl: 'Półpauza — Strona – Witryna' }, value: 'endash' },
|
||
{ label: { en: 'Hyphen — Page - Site', pl: 'Dywiz — Strona - Witryna' }, value: 'hyphen' },
|
||
{ label: { en: 'Bullet — Page · Site', pl: 'Kropka — Strona · Witryna' }, value: 'middot' },
|
||
{ label: { en: 'Slash — Page / Site', pl: 'Ukośnik — Strona / Witryna' }, value: 'slash' },
|
||
],
|
||
},
|
||
],
|
||
},
|
||
]
|