Files
ipal-kit/src/modules/seo/buildNoindexField.ts
T
2026-10-12 14:35:51 +02:00

55 lines
2.0 KiB
TypeScript

import type { CheckboxField, Field } from 'payload'
type BuildNoindexFieldArgs = {
/** Help text under the checkbox. */
description?: string
/** Sidebar label. Default 'Exclude from indexing (noindex)'. */
label?: string
/** Field name for the editor-facing checkbox. Default 'noindex'. */
name?: string
/** Extend/override the generated checkbox (position, access, etc.). */
overrides?: Partial<CheckboxField>
}
/**
* A top-level sidebar `noindex` checkbox. When ticked, the page is excluded from
* `sitemap.xml`, `llms.txt`, site search, and gets `robots: noindex, follow` —
* ALL automatically, no per-project filtering.
*
* Why top-level (not mirrored into `meta.noindex`): plugin-seo's `meta` group
* declares only title/description/image, so Payload silently strips any extra
* key (`meta.noindex`) during sanitization — an earlier version mirrored there
* and the value vanished, leaking noindex pages into the sitemap. The value now
* lives on this top-level field, which persists; every reader in the kit
* (buildSitemapEntries, buildMetadata/createPageMetadata, buildLlmsTxt,
* searchContent) checks `doc.noindex` (and still tolerates a legacy
* `meta.noindex`). One field, one source of truth, zero project glue.
*
* // collections/Pages.ts
* import { buildNoindexField } from '@intecion/ipal-kit'
* fields: [ /* … *\/ buildNoindexField() ],
*/
export function buildNoindexField(args: BuildNoindexFieldArgs = {}): Field {
const {
name = 'noindex',
description = 'Check to exclude this page from indexing (robots: noindex, follow), the sitemap, llms.txt and site search.',
label = 'Exclude from indexing (noindex)',
overrides = {},
} = args
const { admin: adminOverrides, ...restOverrides } = overrides
return {
name,
type: 'checkbox',
admin: {
description,
position: 'sidebar',
...adminOverrides,
},
defaultValue: false,
label,
...restOverrides,
} as CheckboxField
}