Added module Links

This commit is contained in:
2026-10-13 18:04:37 +02:00
parent db05fe814b
commit 3d467d7350
57 changed files with 1786 additions and 777 deletions
+39 -7
View File
@@ -30,7 +30,13 @@ export const AI_TRAINING_BOTS = [
type AiBotsPolicy = 'allow' | 'block-training' | 'disallow' | false
type BuildRobotsArgs = {
export type RobotsOptions = {
/**
* Admin path to disallow. Default '/admin'. With a hidden panel
* (ipalKit adminRoute) pass `false`: robots.txt is public, so listing the
* path would reveal it — the admin is noindex anyway.
*/
adminRoute?: false | string
/** Override the assistant/search bot list. */
aiAssistantAgents?: readonly string[]
/**
@@ -47,14 +53,29 @@ type BuildRobotsArgs = {
aiBots?: AiBotsPolicy
/** Override the training crawler list. */
aiTrainingAgents?: readonly string[]
/** Absolute origin, e.g. 'https://example.com'. */
baseUrl: string
/** Paths to disallow. Defaults to Payload's admin and API. */
/**
* Full disallow list — REPLACES the defaults ([adminRoute, '/api']). Prefer
* `extraDisallow` / `disallowParams`, which add to the defaults instead.
*/
disallow?: string[]
/**
* Query parameters whose URLs crawlers should skip (thin/duplicate pages that
* waste crawl budget), e.g. ['s', 'meter', 'utm_source']. Each becomes
* `/*?name=` and `/*&name=` (the parameter may not be first).
* Don't list `page` — paginated archives are real, canonical-to-self pages.
*/
disallowParams?: string[]
/** Paths added to the default disallow list, e.g. ['/koszyk']. */
extraDisallow?: string[]
/** Whether to advertise the sitemap. Defaults to true. */
sitemap?: boolean
}
type BuildRobotsArgs = {
/** Absolute origin, e.g. 'https://example.com'. */
baseUrl: string
} & RobotsOptions
/**
* Shape for Next's `app/robots.ts`. `rules` may be a single rule or an array
* (Next accepts both) — it becomes an array when AI-bot rules are added.
@@ -86,21 +107,32 @@ export type RobotsRules = {
* PerplexityBot, Google-Extended and friends. To keep AI answers but opt out of
* model training, use `aiBots: 'block-training'`. To block them all, 'disallow'.
*
* Pass custom disallow to block parametrized/thin URLs that waste crawl budget:
* Block parametrized/thin URLs that waste crawl budget — added to the defaults:
* ```ts
* buildRobots({ baseUrl, disallow: ['/admin', '/api', '/*?meter=*', '/*?s=*'] })
* buildRobots({ baseUrl, disallowParams: ['s', 'meter'] })
* // Disallow: /admin, /api, /*?s=, /*&s=, /*?meter=, /*&meter=
* ```
*/
export function buildRobots({
adminRoute = '/admin',
aiAssistantAgents = AI_ASSISTANT_BOTS,
aiBots = 'allow',
aiTrainingAgents = AI_TRAINING_BOTS,
baseUrl,
disallow = ['/admin', '/api'],
disallow: disallowOverride,
disallowParams = [],
extraDisallow = [],
sitemap = true,
}: BuildRobotsArgs): RobotsRules {
const origin = baseUrl.replace(/\/$/, '')
const defaults = [...(adminRoute ? [adminRoute] : []), '/api']
const paramRules = disallowParams
.map((p) => p.trim())
.filter(Boolean)
.flatMap((p) => [`/*?${p}=`, `/*&${p}=`])
const disallow = [...new Set([...(disallowOverride ?? defaults), ...extraDisallow, ...paramRules])]
const baseRule: RobotRule = { allow: '/', disallow, userAgent: '*' }
const aiRules: RobotRule[] = []