Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73eacb09c2 | ||
|
|
2665cfa7b6 |
+1
-1
@@ -47,7 +47,7 @@ import { buildLocalizedPath, getDefaultLocale, isValidLocale } from '../i18n/ind
|
|||||||
if (doc._status && doc._status !== 'published') {
|
if (doc._status && doc._status !== 'published') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (doc.meta?.noindex) {
|
if (doc.noindex || doc.meta?.noindex) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const title = typeof doc.title === 'string' ? doc.title : undefined;
|
const title = typeof doc.title === 'string' ? doc.title : undefined;
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+2
-2
@@ -70,7 +70,7 @@ import { buildLocalizedPath } from '../i18n/index.js';
|
|||||||
if (raw._status && raw._status !== 'published') {
|
if (raw._status && raw._status !== 'published') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (raw.meta?.noindex) {
|
if (raw.noindex || raw.meta?.noindex) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const title = typeof raw.title === 'string' ? raw.title : undefined;
|
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') {
|
if (raw._status && raw._status !== 'published') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (raw.meta?.noindex) {
|
if (raw.noindex || raw.meta?.noindex) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const title = typeof raw.title === 'string' ? raw.title : undefined;
|
const title = typeof raw.title === 'string' ? raw.title : undefined;
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+8
-1
@@ -53,6 +53,13 @@ type BuildMetadataArgs = {
|
|||||||
locale: string;
|
locale: string;
|
||||||
/** SEO meta from the document (plugin-seo group). */
|
/** SEO meta from the document (plugin-seo group). */
|
||||||
meta?: null | SeoMeta;
|
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'. */
|
/** Page title or site name first. Defaults to 'page-first'. */
|
||||||
order?: TitleOrder;
|
order?: TitleOrder;
|
||||||
/**
|
/**
|
||||||
@@ -98,5 +105,5 @@ type BuildMetadataArgs = {
|
|||||||
* pieces (meta group, site name, image URL, localized slugs) and passes them
|
* pieces (meta group, site name, image URL, localized slugs) and passes them
|
||||||
* in — the plugin composes, it doesn't fetch.
|
* 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 {};
|
export {};
|
||||||
|
|||||||
Vendored
+2
-2
@@ -9,7 +9,7 @@ import { buildHreflangAlternates } from './hreflang.js';
|
|||||||
* Designed for use inside Next.js `generateMetadata`. The caller resolves the
|
* Designed for use inside Next.js `generateMetadata`. The caller resolves the
|
||||||
* pieces (meta group, site name, image URL, localized slugs) and passes them
|
* pieces (meta group, site name, image URL, localized slugs) and passes them
|
||||||
* in — the plugin composes, it doesn't fetch.
|
* 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
|
// Title source priority: titleOverride (exact, wins outright) > meta.title
|
||||||
// (SEO title an editor set) > pageTitle (the document's own name). This means
|
// (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')
|
// 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
|
// robots: noindex pages are excluded (follow keeps link authority). Indexed
|
||||||
// pages get generous snippet/preview limits so Google can show rich results
|
// pages get generous snippet/preview limits so Google can show rich results
|
||||||
// (long snippets, large image previews, full video previews).
|
// (long snippets, large image previews, full video previews).
|
||||||
...meta?.noindex ? {
|
...noindex || meta?.noindex ? {
|
||||||
robots: {
|
robots: {
|
||||||
follow: true,
|
follow: true,
|
||||||
index: false
|
index: false
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+12
-15
@@ -2,29 +2,26 @@ import type { CheckboxField, Field } from 'payload';
|
|||||||
type BuildNoindexFieldArgs = {
|
type BuildNoindexFieldArgs = {
|
||||||
/** Help text under the checkbox. */
|
/** Help text under the checkbox. */
|
||||||
description?: string;
|
description?: string;
|
||||||
/** Sidebar label. Default 'Wyklucz z indeksowania (noindex)'. */
|
/** Sidebar label. Default 'Exclude from indexing (noindex)'. */
|
||||||
label?: string;
|
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'. */
|
/** Field name for the editor-facing checkbox. Default 'noindex'. */
|
||||||
name?: string;
|
name?: string;
|
||||||
/** Extend/override the generated checkbox (position, access, etc.). */
|
/** Extend/override the generated checkbox (position, access, etc.). */
|
||||||
overrides?: Partial<CheckboxField>;
|
overrides?: Partial<CheckboxField>;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* A sidebar `noindex` checkbox that mirrors into `meta.noindex` (what the
|
* A top-level sidebar `noindex` checkbox. When ticked, the page is excluded from
|
||||||
* sitemap and metadata generators actually read). Replaces the hand-rolled
|
* `sitemap.xml`, `llms.txt`, site search, and gets `robots: noindex, follow` —
|
||||||
* checkbox + `beforeChange` hook with its `(data as any).meta.noindex = …`
|
* ALL automatically, no per-project filtering.
|
||||||
* glue copied into every project — no `any`, one source of truth for editors,
|
|
||||||
* one stable read location for the engine.
|
|
||||||
*
|
*
|
||||||
* Idempotent and order-independent: if either the checkbox OR an existing
|
* Why top-level (not mirrored into `meta.noindex`): plugin-seo's `meta` group
|
||||||
* `meta.noindex` is set, the page ends up noindex; the two can't drift apart.
|
* 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
|
* // collections/Pages.ts
|
||||||
* import { buildNoindexField } from '@intecion/ipal-kit'
|
* import { buildNoindexField } from '@intecion/ipal-kit'
|
||||||
|
|||||||
+13
-47
@@ -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
|
* A top-level sidebar `noindex` checkbox. When ticked, the page is excluded from
|
||||||
* sitemap and metadata generators actually read). Replaces the hand-rolled
|
* `sitemap.xml`, `llms.txt`, site search, and gets `robots: noindex, follow` —
|
||||||
* checkbox + `beforeChange` hook with its `(data as any).meta.noindex = …`
|
* ALL automatically, no per-project filtering.
|
||||||
* glue copied into every project — no `any`, one source of truth for editors,
|
|
||||||
* one stable read location for the engine.
|
|
||||||
*
|
*
|
||||||
* Idempotent and order-independent: if either the checkbox OR an existing
|
* Why top-level (not mirrored into `meta.noindex`): plugin-seo's `meta` group
|
||||||
* `meta.noindex` is set, the page ends up noindex; the two can't drift apart.
|
* 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
|
* // collections/Pages.ts
|
||||||
* import { buildNoindexField } from '@intecion/ipal-kit'
|
* import { buildNoindexField } from '@intecion/ipal-kit'
|
||||||
* fields: [ /* … *\/ buildNoindexField() ],
|
* fields: [ /* … *\/ buildNoindexField() ],
|
||||||
*/ export function buildNoindexField(args = {}) {
|
*/ 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 { 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 segments = metaPath.split('.');
|
const { admin: adminOverrides, ...restOverrides } = overrides;
|
||||||
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;
|
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
@@ -53,14 +27,6 @@
|
|||||||
...adminOverrides
|
...adminOverrides
|
||||||
},
|
},
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
hooks: {
|
|
||||||
...hooksOverrides,
|
|
||||||
// mirror runs first, then any project-supplied beforeChange hooks.
|
|
||||||
beforeChange: [
|
|
||||||
mirror,
|
|
||||||
...hooksOverrides?.beforeChange ?? []
|
|
||||||
]
|
|
||||||
},
|
|
||||||
label,
|
label,
|
||||||
...restOverrides
|
...restOverrides
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+5
-1
@@ -29,7 +29,11 @@ import { buildHreflangAlternates } from './hreflang.js';
|
|||||||
if (doc._status && doc._status !== 'published') {
|
if (doc._status && doc._status !== 'published') {
|
||||||
return false;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
if (hasExcludedSlug(doc.slug)) {
|
if (hasExcludedSlug(doc.slug)) {
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+1
@@ -90,6 +90,7 @@ import { slugsAcrossLocales } from './slugsAcrossLocales.js';
|
|||||||
...base,
|
...base,
|
||||||
imageUrl: resolveOgImage(doc),
|
imageUrl: resolveOgImage(doc),
|
||||||
meta: doc.meta,
|
meta: doc.meta,
|
||||||
|
noindex: doc.noindex,
|
||||||
pageTitle: doc.title,
|
pageTitle: doc.title,
|
||||||
prefix,
|
prefix,
|
||||||
query,
|
query,
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+20
-8
@@ -731,9 +731,9 @@ Alternatywnie: dodaj `noindex` do System Pages o rolach prawnych automatycznie.
|
|||||||
|
|
||||||
### buildNoindexField — przyjazny checkbox w sidebarze
|
### buildNoindexField — przyjazny checkbox w sidebarze
|
||||||
|
|
||||||
Zamiast własnego checkboxa + hooka z `(data as any).meta.noindex = …` użyj
|
Jeden przełącznik w sidebarze. Zaznaczony → strona **automatycznie** wypada z:
|
||||||
gotowego pola. Jeden przełącznik dla redaktora, zgrany z `meta.noindex` (to
|
`sitemap.xml`, `llms.txt`, wyszukiwarki, i dostaje `robots: noindex, follow` —
|
||||||
czyta sitemap i metadata), bez `any`, bez rozjazdu między dwoma miejscami:
|
bez żadnego ręcznego filtrowania w projekcie.
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { buildNoindexField } from '@intecion/ipal-kit'
|
import { buildNoindexField } from '@intecion/ipal-kit'
|
||||||
@@ -743,10 +743,22 @@ export const Pages: CollectionConfig = {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Idempotentne: jeśli ustawiony checkbox LUB istniejące `meta.noindex` — strona
|
**Pole jest top-level (`doc.noindex`), NIE mirrorowane do `meta.noindex`.**
|
||||||
wychodzi `noindex`; nie da się ich rozjechać. Opcje: `name` (domyślnie
|
Dlaczego: grupa `meta` z plugin-seo deklaruje tylko title/description/image, więc
|
||||||
`'noindex'`), `label`, `description`, `metaPath` (domyślnie `'meta.noindex'`),
|
Payload przy sanityzacji **po cichu wycina** każdy dodatkowy klucz (`meta.noindex`)
|
||||||
`overrides` (pozycja, access itp.).
|
— wcześniejsza wersja mirrorowała tam wartość i znikała, przez co strony noindex
|
||||||
|
trafiały do sitemapy. Teraz wartość żyje na polu top-level (które się zapisuje), a
|
||||||
|
wszystkie czytniki kitu (`buildSitemapEntries`, `buildMetadata`/
|
||||||
|
`createPageMetadata`, `buildLlmsTxt`, `searchContent`) sprawdzają `doc.noindex`
|
||||||
|
(oraz, dla zgodności wstecznej, ewentualne `meta.noindex`). Jedno pole, jedno
|
||||||
|
źródło prawdy, zero kleju w projekcie.
|
||||||
|
|
||||||
|
Opcje: `name` (domyślnie `'noindex'`), `label`, `description`, `overrides`
|
||||||
|
(pozycja, access itp.).
|
||||||
|
|
||||||
|
> Naprawione w 1.7.5 — wcześniej (mirror do `meta.noindex`) strony noindex
|
||||||
|
> potrafiły wyciekać do sitemapy. Po aktualizacji `app/sitemap.xml/route.ts`
|
||||||
|
> wraca do czystej jednolinijki, bez ręcznego filtrowania.
|
||||||
|
|
||||||
## robots.txt — blokada parametrów (crawl budget)
|
## robots.txt — blokada parametrów (crawl budget)
|
||||||
|
|
||||||
@@ -1129,4 +1141,4 @@ const speakable = buildSpeakableJsonLd({
|
|||||||
W markupie projektu oznacz pasujące elementy (np. `className="speakable"` albo
|
W markupie projektu oznacz pasujące elementy (np. `className="speakable"` albo
|
||||||
sekcja `.lead` ze streszczeniem). Selektory nietrafiające w nic są ignorowane —
|
sekcja `.lead` ze streszczeniem). Selektory nietrafiające w nic są ignorowane —
|
||||||
nie wskazuj nawigacji ani boilerplate'u, tylko samodzielny, czytelny tekst.
|
nie wskazuj nawigacji ani boilerplate'u, tylko samodzielny, czytelny tekst.
|
||||||
Dopełnia Markdown/llms: asystent łatwiej wyciąga kluczową treść strony.
|
Dopełnia Markdown/llms: asystent łatwiej wyciąga kluczową treść strony.
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@intecion/ipal-kit",
|
"name": "@intecion/ipal-kit",
|
||||||
"version": "1.7.4",
|
"version": "1.7.6",
|
||||||
"description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.",
|
"description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ type PageRow = {
|
|||||||
_status?: string
|
_status?: string
|
||||||
id: number | string
|
id: number | string
|
||||||
meta?: { description?: unknown; noindex?: boolean } | null
|
meta?: { description?: unknown; noindex?: boolean } | null
|
||||||
|
noindex?: boolean | null
|
||||||
slug?: unknown
|
slug?: unknown
|
||||||
title?: unknown
|
title?: unknown
|
||||||
}
|
}
|
||||||
@@ -91,7 +92,7 @@ export async function searchContent({
|
|||||||
const results: SearchResult[] = []
|
const results: SearchResult[] = []
|
||||||
for (const doc of docs) {
|
for (const doc of docs) {
|
||||||
if (doc._status && doc._status !== 'published') {continue}
|
if (doc._status && doc._status !== 'published') {continue}
|
||||||
if (doc.meta?.noindex) {continue}
|
if (doc.noindex || doc.meta?.noindex) {continue}
|
||||||
const title = typeof doc.title === 'string' ? doc.title : undefined
|
const title = typeof doc.title === 'string' ? doc.title : undefined
|
||||||
const slug = typeof doc.slug === 'string' ? doc.slug : undefined
|
const slug = typeof doc.slug === 'string' ? doc.slug : undefined
|
||||||
if (!title || !slug) {continue}
|
if (!title || !slug) {continue}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ type PageRow = {
|
|||||||
_status?: string
|
_status?: string
|
||||||
id: number | string
|
id: number | string
|
||||||
meta?: { description?: unknown; noindex?: boolean } | null
|
meta?: { description?: unknown; noindex?: boolean } | null
|
||||||
|
noindex?: boolean | null
|
||||||
slug?: unknown
|
slug?: unknown
|
||||||
title?: unknown
|
title?: unknown
|
||||||
}
|
}
|
||||||
@@ -131,7 +132,7 @@ export async function buildLlmsTxt({
|
|||||||
const sections: string[] = []
|
const sections: string[] = []
|
||||||
for (const raw of result.docs as PageRow[]) {
|
for (const raw of result.docs as PageRow[]) {
|
||||||
if (raw._status && raw._status !== 'published') {continue}
|
if (raw._status && raw._status !== 'published') {continue}
|
||||||
if (raw.meta?.noindex) {continue}
|
if (raw.noindex || raw.meta?.noindex) {continue}
|
||||||
|
|
||||||
const title = typeof raw.title === 'string' ? raw.title : undefined
|
const title = typeof raw.title === 'string' ? raw.title : undefined
|
||||||
const slug = typeof raw.slug === 'string' ? raw.slug : undefined
|
const slug = typeof raw.slug === 'string' ? raw.slug : undefined
|
||||||
@@ -153,7 +154,7 @@ export async function buildLlmsTxt({
|
|||||||
const pageLinks: string[] = []
|
const pageLinks: string[] = []
|
||||||
for (const raw of result.docs as PageRow[]) {
|
for (const raw of result.docs as PageRow[]) {
|
||||||
if (raw._status && raw._status !== 'published') {continue}
|
if (raw._status && raw._status !== 'published') {continue}
|
||||||
if (raw.meta?.noindex) {continue}
|
if (raw.noindex || raw.meta?.noindex) {continue}
|
||||||
|
|
||||||
const title = typeof raw.title === 'string' ? raw.title : undefined
|
const title = typeof raw.title === 'string' ? raw.title : undefined
|
||||||
const slug = typeof raw.slug === 'string' ? raw.slug : undefined
|
const slug = typeof raw.slug === 'string' ? raw.slug : undefined
|
||||||
|
|||||||
@@ -57,6 +57,13 @@ type BuildMetadataArgs = {
|
|||||||
locale: string
|
locale: string
|
||||||
/** SEO meta from the document (plugin-seo group). */
|
/** SEO meta from the document (plugin-seo group). */
|
||||||
meta?: null | SeoMeta
|
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'. */
|
/** Page title or site name first. Defaults to 'page-first'. */
|
||||||
order?: TitleOrder
|
order?: TitleOrder
|
||||||
/**
|
/**
|
||||||
@@ -110,6 +117,7 @@ export function buildMetadata({
|
|||||||
imageUrl,
|
imageUrl,
|
||||||
locale,
|
locale,
|
||||||
meta,
|
meta,
|
||||||
|
noindex,
|
||||||
order,
|
order,
|
||||||
pageTitle,
|
pageTitle,
|
||||||
prefix,
|
prefix,
|
||||||
@@ -163,7 +171,7 @@ export function buildMetadata({
|
|||||||
// robots: noindex pages are excluded (follow keeps link authority). Indexed
|
// robots: noindex pages are excluded (follow keeps link authority). Indexed
|
||||||
// pages get generous snippet/preview limits so Google can show rich results
|
// pages get generous snippet/preview limits so Google can show rich results
|
||||||
// (long snippets, large image previews, full video previews).
|
// (long snippets, large image previews, full video previews).
|
||||||
...(meta?.noindex
|
...(noindex || meta?.noindex
|
||||||
? { robots: { follow: true, index: false } }
|
? { robots: { follow: true, index: false } }
|
||||||
: {
|
: {
|
||||||
robots: {
|
robots: {
|
||||||
|
|||||||
@@ -1,54 +1,29 @@
|
|||||||
import type { CheckboxField, Field, FieldHook } from 'payload'
|
import type { CheckboxField, Field } from 'payload'
|
||||||
|
|
||||||
type BuildNoindexFieldArgs = {
|
type BuildNoindexFieldArgs = {
|
||||||
/** Help text under the checkbox. */
|
/** Help text under the checkbox. */
|
||||||
description?: string
|
description?: string
|
||||||
/** Sidebar label. Default 'Wyklucz z indeksowania (noindex)'. */
|
/** Sidebar label. Default 'Exclude from indexing (noindex)'. */
|
||||||
label?: string
|
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'. */
|
/** Field name for the editor-facing checkbox. Default 'noindex'. */
|
||||||
name?: string
|
name?: string
|
||||||
/** Extend/override the generated checkbox (position, access, etc.). */
|
/** Extend/override the generated checkbox (position, access, etc.). */
|
||||||
overrides?: Partial<CheckboxField>
|
overrides?: Partial<CheckboxField>
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Read a dotted path (e.g. 'meta.noindex') off a loosely-typed object. */
|
|
||||||
function readPath(obj: null | Record<string, unknown> | undefined, path: string[]): unknown {
|
|
||||||
let cur: unknown = obj
|
|
||||||
for (const key of path) {
|
|
||||||
if (cur == null || typeof cur !== 'object') {return undefined}
|
|
||||||
cur = (cur as Record<string, unknown>)[key]
|
|
||||||
}
|
|
||||||
return cur
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Write a dotted path, creating intermediate objects as needed. */
|
|
||||||
function writePath(obj: Record<string, unknown>, path: string[], value: unknown): void {
|
|
||||||
let cur: Record<string, unknown> = 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] as Record<string, unknown>
|
|
||||||
}
|
|
||||||
cur[path[path.length - 1]] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A sidebar `noindex` checkbox that mirrors into `meta.noindex` (what the
|
* A top-level sidebar `noindex` checkbox. When ticked, the page is excluded from
|
||||||
* sitemap and metadata generators actually read). Replaces the hand-rolled
|
* `sitemap.xml`, `llms.txt`, site search, and gets `robots: noindex, follow` —
|
||||||
* checkbox + `beforeChange` hook with its `(data as any).meta.noindex = …`
|
* ALL automatically, no per-project filtering.
|
||||||
* glue copied into every project — no `any`, one source of truth for editors,
|
|
||||||
* one stable read location for the engine.
|
|
||||||
*
|
*
|
||||||
* Idempotent and order-independent: if either the checkbox OR an existing
|
* Why top-level (not mirrored into `meta.noindex`): plugin-seo's `meta` group
|
||||||
* `meta.noindex` is set, the page ends up noindex; the two can't drift apart.
|
* 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
|
* // collections/Pages.ts
|
||||||
* import { buildNoindexField } from '@intecion/ipal-kit'
|
* import { buildNoindexField } from '@intecion/ipal-kit'
|
||||||
@@ -57,23 +32,12 @@ function writePath(obj: Record<string, unknown>, path: string[], value: unknown)
|
|||||||
export function buildNoindexField(args: BuildNoindexFieldArgs = {}): Field {
|
export function buildNoindexField(args: BuildNoindexFieldArgs = {}): Field {
|
||||||
const {
|
const {
|
||||||
name = 'noindex',
|
name = 'noindex',
|
||||||
description = 'Check to exclude this page from indexing (robots: noindex, follow) and from sitemap.xml.',
|
description = 'Check to exclude this page from indexing (robots: noindex, follow), the sitemap, llms.txt and site search.',
|
||||||
label = 'Exclude from indexing (noindex)',
|
label = 'Exclude from indexing (noindex)',
|
||||||
metaPath = 'meta.noindex',
|
|
||||||
overrides = {},
|
overrides = {},
|
||||||
} = args
|
} = args
|
||||||
|
|
||||||
const segments = metaPath.split('.')
|
const { admin: adminOverrides, ...restOverrides } = overrides
|
||||||
|
|
||||||
const mirror: FieldHook = ({ data, value }) => {
|
|
||||||
const shouldNoindex = Boolean(value ?? readPath(data as Record<string, unknown>, segments))
|
|
||||||
if (data && typeof data === 'object') {
|
|
||||||
writePath(data as Record<string, unknown>, segments, shouldNoindex)
|
|
||||||
}
|
|
||||||
return shouldNoindex
|
|
||||||
}
|
|
||||||
|
|
||||||
const { admin: adminOverrides, hooks: hooksOverrides, ...restOverrides } = overrides
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
@@ -84,11 +48,6 @@ export function buildNoindexField(args: BuildNoindexFieldArgs = {}): Field {
|
|||||||
...adminOverrides,
|
...adminOverrides,
|
||||||
},
|
},
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
hooks: {
|
|
||||||
...hooksOverrides,
|
|
||||||
// mirror runs first, then any project-supplied beforeChange hooks.
|
|
||||||
beforeChange: [mirror, ...(hooksOverrides?.beforeChange ?? [])],
|
|
||||||
},
|
|
||||||
label,
|
label,
|
||||||
...restOverrides,
|
...restOverrides,
|
||||||
} as CheckboxField
|
} as CheckboxField
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ type DocRow = {
|
|||||||
_status?: string
|
_status?: string
|
||||||
id: number | string
|
id: number | string
|
||||||
meta?: { noindex?: boolean } | null
|
meta?: { noindex?: boolean } | null
|
||||||
|
/** Top-level checkbox (buildNoindexField) — the field that actually persists. */
|
||||||
|
noindex?: boolean | null
|
||||||
slug?: unknown
|
slug?: unknown
|
||||||
updatedAt?: string
|
updatedAt?: string
|
||||||
}
|
}
|
||||||
@@ -78,7 +80,11 @@ function hasExcludedSlug(slug: unknown): boolean {
|
|||||||
/** Skip drafts, noindex, and system/error pages (404 etc.). */
|
/** Skip drafts, noindex, and system/error pages (404 etc.). */
|
||||||
function isIndexable(doc: DocRow): boolean {
|
function isIndexable(doc: DocRow): boolean {
|
||||||
if (doc._status && doc._status !== 'published') {return false}
|
if (doc._status && doc._status !== 'published') {return false}
|
||||||
if (doc.meta?.noindex) {return false}
|
// 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)) {return false}
|
if (hasExcludedSlug(doc.slug)) {return false}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ type PageMetadataContext = {
|
|||||||
type DocShape = {
|
type DocShape = {
|
||||||
id: number | string
|
id: number | string
|
||||||
meta?: null | SeoMeta
|
meta?: null | SeoMeta
|
||||||
|
/** Top-level noindex checkbox (buildNoindexField) — the field that persists. */
|
||||||
|
noindex?: boolean | null
|
||||||
/** The document's own title (page name), used as the fallback page title. */
|
/** The document's own title (page name), used as the fallback page title. */
|
||||||
title?: null | string
|
title?: null | string
|
||||||
}
|
}
|
||||||
@@ -153,6 +155,7 @@ export function createPageMetadata(args: CreatePageMetadataArgs) {
|
|||||||
...base,
|
...base,
|
||||||
imageUrl: resolveOgImage(doc),
|
imageUrl: resolveOgImage(doc),
|
||||||
meta: doc.meta,
|
meta: doc.meta,
|
||||||
|
noindex: doc.noindex,
|
||||||
pageTitle: doc.title,
|
pageTitle: doc.title,
|
||||||
prefix,
|
prefix,
|
||||||
query,
|
query,
|
||||||
|
|||||||
Reference in New Issue
Block a user