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:
@@ -105,10 +105,8 @@ export function createMarkdownRenderer(args: CreateMarkdownRendererArgs = {}) {
|
||||
const fm = ['---', `locale: ${locale}`]
|
||||
if (title) {fm.push(`title: ${yamlEscape(title)}`)}
|
||||
if (description) {fm.push(`description: ${yamlEscape(description)}`)}
|
||||
if (baseUrl) {
|
||||
const segments = config?.locales.length === 1 ? (slug ?? []) : [locale, ...(slug ?? [])]
|
||||
fm.push(`url: ${baseUrl.replace(/\/$/, '')}/${segments.join('/')}`.replace(/\/$/, ''))
|
||||
}
|
||||
const url = canonicalOf(baseUrl, config, locale, slug)
|
||||
if (url) {fm.push(`url: ${url}`)}
|
||||
if (typeof doc.updatedAt === 'string') {fm.push(`updated: ${doc.updatedAt.slice(0, 10)}`)}
|
||||
fm.push('---')
|
||||
parts.push(fm.join('\n'))
|
||||
@@ -127,7 +125,7 @@ export function createMarkdownRenderer(args: CreateMarkdownRendererArgs = {}) {
|
||||
* Wraps a Markdown string in a `text/markdown` Response, or a 404 when null.
|
||||
* Uses the global Response — no next/server import.
|
||||
*/
|
||||
export function markdownResponse(md: null | string): Response {
|
||||
export function markdownResponse(md: null | string, options: { canonical?: string } = {}): Response {
|
||||
if (md == null) {
|
||||
return new Response('Not found', { headers: { 'content-type': 'text/plain' }, status: 404 })
|
||||
}
|
||||
@@ -135,11 +133,22 @@ export function markdownResponse(md: null | string): Response {
|
||||
headers: {
|
||||
'cache-control': 'public, max-age=0, s-maxage=3600, stale-while-revalidate=86400',
|
||||
'content-type': 'text/markdown; charset=utf-8',
|
||||
// A mirror of an HTML page: AI agents read it, search engines must not
|
||||
// index it as a duplicate — and should credit the HTML page instead.
|
||||
'x-robots-tag': 'noindex',
|
||||
...(options.canonical ? { link: `<${options.canonical}>; rel="canonical"` } : {}),
|
||||
},
|
||||
status: 200,
|
||||
})
|
||||
}
|
||||
|
||||
/** Canonical HTML URL of a Markdown page — same rule as the frontmatter `url:`. */
|
||||
function canonicalOf(baseUrl: string | undefined, config: { locales: readonly unknown[] } | undefined, locale: string, slug?: string[]) {
|
||||
if (!baseUrl) {return undefined}
|
||||
const segments = config?.locales.length === 1 ? (slug ?? []) : [locale, ...(slug ?? [])]
|
||||
return `${baseUrl.replace(/\/$/, '')}/${segments.join('/')}`.replace(/\/$/, '')
|
||||
}
|
||||
|
||||
type MarkdownRouteContext = { params: Promise<{ locale: string; slug?: string[] }> }
|
||||
|
||||
/**
|
||||
@@ -167,7 +176,8 @@ export function createMarkdownRoute(
|
||||
GET: async (_req, { params }) => {
|
||||
try {
|
||||
const { slug, locale } = await params
|
||||
return markdownResponse(await render({ slug, locale, payload: await getCachedPayload() }))
|
||||
const md = await render({ slug, locale, payload: await getCachedPayload() })
|
||||
return markdownResponse(md, { canonical: canonicalOf(rendererArgs.baseUrl, rendererArgs.config, locale, slug) })
|
||||
} catch (err) {
|
||||
console.warn('[ipal] createMarkdownRoute: render failed:', err)
|
||||
return new Response('Service unavailable', { headers: { 'content-type': 'text/plain' }, status: 503 })
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { isSiteNoindex } from '../seo/siteNoindex.js'
|
||||
|
||||
/**
|
||||
* A single HTTP header, in the shape Next.js next.config headers() expects.
|
||||
*/
|
||||
@@ -116,6 +118,11 @@ export function buildSecurityHeaders(args: BuildSecurityHeadersArgs = {}): Secur
|
||||
headers.push({ key: 'Cross-Origin-Opener-Policy', value: coop })
|
||||
}
|
||||
|
||||
// Staging / preview (IPAL_NOINDEX=1): keep every response out of search engines.
|
||||
if (isSiteNoindex()) {
|
||||
headers.push({ key: 'X-Robots-Tag', value: 'noindex, nofollow' })
|
||||
}
|
||||
|
||||
// Merge additional: same-key entries override the defaults above.
|
||||
for (const extra of additional) {
|
||||
const i = headers.findIndex((h) => h.key.toLowerCase() === extra.key.toLowerCase())
|
||||
|
||||
@@ -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