noindex fix

This commit is contained in:
2026-10-12 14:35:51 +02:00
parent 5c466b664c
commit 2665cfa7b6
22 changed files with 110 additions and 145 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ import { buildLocalizedPath, getDefaultLocale, isValidLocale } from '../i18n/ind
if (doc._status && doc._status !== 'published') {
continue;
}
if (doc.meta?.noindex) {
if (doc.noindex || doc.meta?.noindex) {
continue;
}
const title = typeof doc.title === 'string' ? doc.title : undefined;
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -70,7 +70,7 @@ import { buildLocalizedPath } from '../i18n/index.js';
if (raw._status && raw._status !== 'published') {
continue;
}
if (raw.meta?.noindex) {
if (raw.noindex || raw.meta?.noindex) {
continue;
}
const title = typeof raw.title === 'string' ? raw.title : undefined;
@@ -111,7 +111,7 @@ import { buildLocalizedPath } from '../i18n/index.js';
if (raw._status && raw._status !== 'published') {
continue;
}
if (raw.meta?.noindex) {
if (raw.noindex || raw.meta?.noindex) {
continue;
}
const title = typeof raw.title === 'string' ? raw.title : undefined;
File diff suppressed because one or more lines are too long
+8 -1
View File
@@ -53,6 +53,13 @@ type BuildMetadataArgs = {
locale: string;
/** SEO meta from the document (plugin-seo group). */
meta?: null | SeoMeta;
/**
* Top-level noindex flag (buildNoindexField). Checked alongside meta.noindex:
* plugin-seo's meta group doesn't declare noindex, so a mirror into
* meta.noindex is stripped on save — the top-level field is the one that
* persists. Either being true emits robots index:false.
*/
noindex?: boolean | null;
/** Page title or site name first. Defaults to 'page-first'. */
order?: TitleOrder;
/**
@@ -98,5 +105,5 @@ type BuildMetadataArgs = {
* pieces (meta group, site name, image URL, localized slugs) and passes them
* in — the plugin composes, it doesn't fetch.
*/
export declare function buildMetadata({ baseUrl, config, homeSlug, imageUrl, locale, meta, order, pageTitle, prefix, query, separator, siteDescription, siteName, slugs, }: BuildMetadataArgs): PageMetadata;
export declare function buildMetadata({ baseUrl, config, homeSlug, imageUrl, locale, meta, noindex, order, pageTitle, prefix, query, separator, siteDescription, siteName, slugs, }: BuildMetadataArgs): PageMetadata;
export {};
+2 -2
View File
@@ -9,7 +9,7 @@ import { buildHreflangAlternates } from './hreflang.js';
* Designed for use inside Next.js `generateMetadata`. The caller resolves the
* pieces (meta group, site name, image URL, localized slugs) and passes them
* in — the plugin composes, it doesn't fetch.
*/ export function buildMetadata({ baseUrl, config, homeSlug = 'home', imageUrl, locale, meta, order, pageTitle, prefix, query, separator, siteDescription, siteName, slugs }) {
*/ export function buildMetadata({ baseUrl, config, homeSlug = 'home', imageUrl, locale, meta, noindex, order, pageTitle, prefix, query, separator, siteDescription, siteName, slugs }) {
// Title source priority: titleOverride (exact, wins outright) > meta.title
// (SEO title an editor set) > pageTitle (the document's own name). This means
// a page with no SEO title still shows its name (e.g. 'Sprzątanie biur')
@@ -83,7 +83,7 @@ import { buildHreflangAlternates } from './hreflang.js';
// robots: noindex pages are excluded (follow keeps link authority). Indexed
// pages get generous snippet/preview limits so Google can show rich results
// (long snippets, large image previews, full video previews).
...meta?.noindex ? {
...noindex || meta?.noindex ? {
robots: {
follow: true,
index: false
File diff suppressed because one or more lines are too long
+12 -15
View File
@@ -2,29 +2,26 @@ import type { CheckboxField, Field } from 'payload';
type BuildNoindexFieldArgs = {
/** Help text under the checkbox. */
description?: string;
/** Sidebar label. Default 'Wyklucz z indeksowania (noindex)'. */
/** Sidebar label. Default 'Exclude from indexing (noindex)'. */
label?: string;
/**
* Dotted path, inside the document, that the SEO read path (metadata +
* sitemap) consumes. Default 'meta.noindex' — the plugin-seo `meta` group.
* The checkbox value is mirrored here on every save, so editors toggle one
* friendly switch and the machinery reads a stable location.
*/
metaPath?: string;
/** Field name for the editor-facing checkbox. Default 'noindex'. */
name?: string;
/** Extend/override the generated checkbox (position, access, etc.). */
overrides?: Partial<CheckboxField>;
};
/**
* A sidebar `noindex` checkbox that mirrors into `meta.noindex` (what the
* sitemap and metadata generators actually read). Replaces the hand-rolled
* checkbox + `beforeChange` hook with its `(data as any).meta.noindex = …`
* glue copied into every project — no `any`, one source of truth for editors,
* one stable read location for the engine.
* 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.
*
* Idempotent and order-independent: if either the checkbox OR an existing
* `meta.noindex` is set, the page ends up noindex; the two can't drift apart.
* 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'
+13 -47
View File
@@ -1,49 +1,23 @@
/** Read a dotted path (e.g. 'meta.noindex') off a loosely-typed object. */ function readPath(obj, path) {
let cur = obj;
for (const key of path){
if (cur == null || typeof cur !== 'object') {
return undefined;
}
cur = cur[key];
}
return cur;
}
/** Write a dotted path, creating intermediate objects as needed. */ function writePath(obj, path, value) {
let cur = obj;
for(let i = 0; i < path.length - 1; i++){
const key = path[i];
const next = cur[key];
if (next == null || typeof next !== 'object') {
cur[key] = {};
}
cur = cur[key];
}
cur[path[path.length - 1]] = value;
}
/**
* A sidebar `noindex` checkbox that mirrors into `meta.noindex` (what the
* sitemap and metadata generators actually read). Replaces the hand-rolled
* checkbox + `beforeChange` hook with its `(data as any).meta.noindex = …`
* glue copied into every project — no `any`, one source of truth for editors,
* one stable read location for the engine.
* 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.
*
* Idempotent and order-independent: if either the checkbox OR an existing
* `meta.noindex` is set, the page ends up noindex; the two can't drift apart.
* 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 = {}) {
const { name = 'noindex', description = 'Check to exclude this page from indexing (robots: noindex, follow) and from sitemap.xml.', label = 'Exclude from indexing (noindex)', metaPath = 'meta.noindex', overrides = {} } = args;
const segments = metaPath.split('.');
const mirror = ({ data, value })=>{
const shouldNoindex = Boolean(value ?? readPath(data, segments));
if (data && typeof data === 'object') {
writePath(data, segments, shouldNoindex);
}
return shouldNoindex;
};
const { admin: adminOverrides, hooks: hooksOverrides, ...restOverrides } = overrides;
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',
@@ -53,14 +27,6 @@
...adminOverrides
},
defaultValue: false,
hooks: {
...hooksOverrides,
// mirror runs first, then any project-supplied beforeChange hooks.
beforeChange: [
mirror,
...hooksOverrides?.beforeChange ?? []
]
},
label,
...restOverrides
};
File diff suppressed because one or more lines are too long
+5 -1
View File
@@ -29,7 +29,11 @@ import { buildHreflangAlternates } from './hreflang.js';
if (doc._status && doc._status !== 'published') {
return false;
}
if (doc.meta?.noindex) {
// Check BOTH the top-level checkbox (buildNoindexField, the field that
// persists) AND meta.noindex — plugin-seo's meta group doesn't declare
// noindex, so a mirror into meta.noindex is stripped on save. Reading both
// makes exclusion automatic regardless of where the flag ended up.
if (doc.noindex || doc.meta?.noindex) {
return false;
}
if (hasExcludedSlug(doc.slug)) {
File diff suppressed because one or more lines are too long
+1
View File
@@ -90,6 +90,7 @@ import { slugsAcrossLocales } from './slugsAcrossLocales.js';
...base,
imageUrl: resolveOgImage(doc),
meta: doc.meta,
noindex: doc.noindex,
pageTitle: doc.title,
prefix,
query,
File diff suppressed because one or more lines are too long