noindex tooling, content/noindex/component/testing guidelines for agents
- IPAL_NOINDEX=1: whole-site noindex for staging (robots Disallow /, robots meta noindex,nofollow, X-Robots-Tag via buildSecurityHeaders). - Markdown mirrors and llms files: X-Robots-Tag noindex; Markdown adds a Link rel=canonical to the HTML page. - buildNoindexField refuses noindex on the homepage and archive pages. - AGENT.md §0c: writing pages for Google and AI (structure, answer-first, facts, E-E-A-T, entity consistency, sameAs, aiSummary, meta) and a when-to-noindex table (legal pages stay indexed by default; drafts instead of noindexed pages; staging via env). - AGENT.md §6.0: ten component rules (small, Button styled once, buttons as '+ Add Button' array, variants, panel clarity); audit warns on buttons styled inside sections. - AGENT.md §8a + smoke.spec.template.ts: what to test in a client project; PROGRAMISTA §8.1a: how the plugin itself is tested. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { isSiteNoindex } from './siteNoindex.js'
|
||||
import type { I18nConfig, LocalizedSlugs } from '../i18n/index.js'
|
||||
import type { TitleOrder } from './composeTitle.js'
|
||||
import type { SeoMeta } from './types.js'
|
||||
@@ -205,7 +206,9 @@ export function buildMetadata({
|
||||
// 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).
|
||||
...(noindex || meta?.noindex
|
||||
...(isSiteNoindex()
|
||||
? { robots: { follow: false, index: false } }
|
||||
: noindex || meta?.noindex
|
||||
? { robots: { follow: true, index: false } }
|
||||
: {
|
||||
robots: {
|
||||
|
||||
@@ -9,8 +9,17 @@ type BuildNoindexFieldArgs = {
|
||||
name?: string
|
||||
/** Extend/override the generated checkbox (position, access, etc.). */
|
||||
overrides?: Partial<CheckboxField>
|
||||
/**
|
||||
* Refuse noindex on the homepage and on archive pages (blog, offers…) — it
|
||||
* would drop the whole site or the whole section from Google. Default true.
|
||||
*/
|
||||
protectSystemPages?: boolean
|
||||
/** SiteSettings global read for that check. Default 'site-settings'. */
|
||||
settingsSlug?: string
|
||||
}
|
||||
|
||||
const idOf = (rel: unknown): unknown => (rel && typeof rel === 'object' ? (rel as { id?: unknown }).id : rel)
|
||||
|
||||
/**
|
||||
* A top-level sidebar `noindex` checkbox. When ticked, the page is excluded from
|
||||
* `sitemap.xml`, `llms.txt`, site search, and gets `robots: noindex, follow` —
|
||||
@@ -35,8 +44,28 @@ export function buildNoindexField(args: BuildNoindexFieldArgs = {}): Field {
|
||||
description = 'Check to exclude this page from indexing (robots: noindex, follow), the sitemap, llms.txt and site search.',
|
||||
label = 'Exclude from indexing (noindex)',
|
||||
overrides = {},
|
||||
protectSystemPages = true,
|
||||
settingsSlug = 'site-settings',
|
||||
} = args
|
||||
|
||||
const validate: CheckboxField['validate'] = async (value, { id, req }) => {
|
||||
if (!protectSystemPages || value !== true || id === undefined) {return true}
|
||||
try {
|
||||
const settings = (await req.payload.findGlobal({ slug: settingsSlug as never, depth: 0, req })) as Record<string, unknown>
|
||||
if (idOf(settings.homepage) === id) {
|
||||
return 'This page is the homepage (Site Settings → System Pages). noindex would remove the whole site from Google.'
|
||||
}
|
||||
for (const [key, rel] of Object.entries(settings)) {
|
||||
if (key.endsWith('Archive') && idOf(rel) === id) {
|
||||
return 'This page is an archive (Site Settings → System Pages). noindex would hide the page that lists all its entries.'
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// settings unreadable (fresh DB) — nothing to protect yet
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
const { admin: adminOverrides, ...restOverrides } = overrides
|
||||
|
||||
return {
|
||||
@@ -49,6 +78,7 @@ export function buildNoindexField(args: BuildNoindexFieldArgs = {}): Field {
|
||||
},
|
||||
defaultValue: false,
|
||||
label,
|
||||
validate,
|
||||
...restOverrides,
|
||||
} as CheckboxField
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { isSiteNoindex } from './siteNoindex.js'
|
||||
|
||||
type RobotRule = { allow?: string; disallow?: string[]; userAgent: string | string[] }
|
||||
|
||||
/**
|
||||
@@ -125,6 +127,8 @@ export function buildRobots({
|
||||
sitemap = true,
|
||||
}: BuildRobotsArgs): RobotsRules {
|
||||
const origin = baseUrl.replace(/\/$/, '')
|
||||
// Staging / preview (IPAL_NOINDEX=1): nothing may be crawled.
|
||||
if (isSiteNoindex()) {return { rules: { disallow: ['/'], userAgent: '*' } }}
|
||||
|
||||
const defaults = [...(adminRoute ? [adminRoute] : []), '/api']
|
||||
const paramRules = disallowParams
|
||||
|
||||
@@ -54,7 +54,9 @@ export function createLlmsTxtRoute(opts: {
|
||||
summaryField: opts.summaryField,
|
||||
})
|
||||
return new Response(body, {
|
||||
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
|
||||
// For AI agents, not a search result: keep it (and the full-content
|
||||
// copy, a duplicate of every page) out of search indexes.
|
||||
headers: { 'Content-Type': 'text/plain; charset=utf-8', 'X-Robots-Tag': 'noindex' },
|
||||
})
|
||||
} catch (err) {
|
||||
// DB unreachable at build (container) — return a minimal valid file so the
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Whole-site noindex for staging, previews and test copies: set IPAL_NOINDEX=1
|
||||
* in that environment's env. Then robots.txt disallows everything, every page
|
||||
* gets `robots: noindex, nofollow`, and buildSecurityHeaders adds
|
||||
* `X-Robots-Tag: noindex, nofollow` to every response (files and API too).
|
||||
* Production never sets it — a forgotten staging copy indexed by Google is a
|
||||
* duplicate of the real site.
|
||||
*/
|
||||
export const SITE_NOINDEX_ENV = 'IPAL_NOINDEX'
|
||||
|
||||
export function isSiteNoindex(): boolean {
|
||||
const v = process.env[SITE_NOINDEX_ENV]?.trim().toLowerCase()
|
||||
return v === '1' || v === 'true' || v === 'yes'
|
||||
}
|
||||
Reference in New Issue
Block a user