feat: v1.7.0 — AI-readability suite, form engine & boilerplate helpers
AI / GEO: - feat(content): lexicalToMarkdown, blocksToMarkdown, createMarkdownRenderer (+markdownResponse) — per-page Markdown for AI agents - feat(content): markdown content negotiation + discovery (prefersMarkdown, markdownHref) - feat(seo): buildRobots aiBots policy (allow/block-training/disallow) - feat(seo): llms-full.txt mode in buildLlmsTxt/createLlmsTxtRoute - feat(mcp): createMcpRoute — read-only MCP server (search_content, get_page) - feat(content): searchContent + createSearchRoute — shared JSON search - feat(seo): buildSpeakableJsonLd + buildSummaryField (aiSummary, auto-fill) Forms: - feat(forms): useForm/useContactForm + validators (logic-only, no markup) - feat(forms): honeypot anti-spam (honeypotInputProps, isHoneypotTripped) Helpers / hardening: - feat(i18n): resolveLocalized — replaces ad-hoc getSafeString - feat(hooks): buildCrossLocaleFieldSync — locales from config, no hardcoded list - feat(seo): buildNoindexField — checkbox → meta.noindex, no - feat(content): resolveRedirect — 301/308 from slugHistory - feat(env): assertEnv + ipalEnvRules — fail-fast env validation - feat(consent): ConsentScript — load third-party only after consent - feat(health): createHealthRoute — Coolify/Docker DB liveness Fixes: - fix(seo): wrap getCachedPayload in try/catch in createManifestHandler (Docker/CI build no longer crashes when DB unreachable) docs: migration.md (20 sections), new env.md/mcp.md, updated agents.md, AGENTS-TEMPLATE.md, forms/hooks/content/seo/consent/deployment/richtext
This commit is contained in:
Vendored
+15
-1
@@ -4,6 +4,15 @@ type BuildLlmsTxtArgs = {
|
||||
/** Absolute site URL (https://…). */
|
||||
baseUrl: string;
|
||||
config: I18nConfig;
|
||||
/**
|
||||
* Full-content mode (llms-full.txt). When true, each page's full body is
|
||||
* inlined as Markdown (via blocksToMarkdown) under its heading, so an agent
|
||||
* gets the whole site in one request — the llmstxt.org "llms-full.txt"
|
||||
* convention. Default false = the compact index (links + descriptions).
|
||||
*/
|
||||
full?: boolean;
|
||||
/** Field holding the block layout (full mode only). Default 'layout'. */
|
||||
layoutField?: string;
|
||||
/** Locale for names/descriptions. Defaults to config.defaultLocale. */
|
||||
locale?: string;
|
||||
/** Pages collection slug. Defaults to 'pages'. */
|
||||
@@ -11,6 +20,11 @@ type BuildLlmsTxtArgs = {
|
||||
payload: BasePayload;
|
||||
/** Site settings global slug. Defaults to 'site-settings'. */
|
||||
settingsSlug?: string;
|
||||
/**
|
||||
* Field holding a richer AI summary (buildSummaryField). When set and present,
|
||||
* it's used as the page description instead of meta.description.
|
||||
*/
|
||||
summaryField?: string;
|
||||
};
|
||||
/**
|
||||
* Builds the body of /llms.txt — a Markdown file describing the site for AI
|
||||
@@ -41,5 +55,5 @@ type BuildLlmsTxtArgs = {
|
||||
* Data comes from the panel (siteName, siteDescription, pages) — nothing
|
||||
* hardcoded. Skips drafts and noindex pages (same as the sitemap).
|
||||
*/
|
||||
export declare function buildLlmsTxt({ baseUrl, config, locale, pagesSlug, payload, settingsSlug, }: BuildLlmsTxtArgs): Promise<string>;
|
||||
export declare function buildLlmsTxt({ baseUrl, config, full, layoutField, locale, pagesSlug, payload, settingsSlug, summaryField, }: BuildLlmsTxtArgs): Promise<string>;
|
||||
export {};
|
||||
|
||||
Vendored
+55
-3
@@ -1,3 +1,4 @@
|
||||
import { blocksToMarkdown } from '../content/blocksToMarkdown.js';
|
||||
import { buildLocalizedPath } from '../i18n/index.js';
|
||||
/**
|
||||
* Builds the body of /llms.txt — a Markdown file describing the site for AI
|
||||
@@ -27,7 +28,13 @@ import { buildLocalizedPath } from '../i18n/index.js';
|
||||
*
|
||||
* Data comes from the panel (siteName, siteDescription, pages) — nothing
|
||||
* hardcoded. Skips drafts and noindex pages (same as the sitemap).
|
||||
*/ export async function buildLlmsTxt({ baseUrl, config, locale, pagesSlug = 'pages', payload, settingsSlug = 'site-settings' }) {
|
||||
*/ export async function buildLlmsTxt({ baseUrl, config, full = false, layoutField = 'layout', locale, pagesSlug = 'pages', payload, settingsSlug = 'site-settings', summaryField }) {
|
||||
const pickDescription = (raw)=>{
|
||||
if (summaryField && typeof raw[summaryField] === 'string' && raw[summaryField].trim()) {
|
||||
return raw[summaryField].trim();
|
||||
}
|
||||
return typeof raw.meta?.description === 'string' ? raw.meta.description : undefined;
|
||||
};
|
||||
const loc = locale ?? config.defaultLocale;
|
||||
const origin = baseUrl.replace(/\/$/, '');
|
||||
const settings = await payload.findGlobal({
|
||||
@@ -42,9 +49,10 @@ import { buildLocalizedPath } from '../i18n/index.js';
|
||||
// "path cannot be queried: _status" (a real bug report). Draft filtering
|
||||
// happens in memory below, which is safe for every collection. Same as
|
||||
// buildSitemapEntries and generateStaticParams.
|
||||
// Full mode needs depth:1 so block images/relations populate for the Markdown.
|
||||
const result = await payload.find({
|
||||
collection: pagesSlug,
|
||||
depth: 0,
|
||||
depth: full ? 1 : 0,
|
||||
limit: 1000,
|
||||
locale: loc
|
||||
});
|
||||
@@ -55,6 +63,49 @@ import { buildLocalizedPath } from '../i18n/index.js';
|
||||
if (description) {
|
||||
lines.push(`> ${description}`, '');
|
||||
}
|
||||
if (full) {
|
||||
// Full-content: each published page inlined as Markdown under its heading.
|
||||
const sections = [];
|
||||
for (const raw of result.docs){
|
||||
if (raw._status && raw._status !== 'published') {
|
||||
continue;
|
||||
}
|
||||
if (raw.meta?.noindex) {
|
||||
continue;
|
||||
}
|
||||
const title = typeof raw.title === 'string' ? raw.title : undefined;
|
||||
const slug = typeof raw.slug === 'string' ? raw.slug : undefined;
|
||||
if (!title || !slug) {
|
||||
continue;
|
||||
}
|
||||
const path = buildLocalizedPath({
|
||||
config,
|
||||
locale: loc,
|
||||
slugs: {
|
||||
[loc]: slug
|
||||
}
|
||||
});
|
||||
const body = blocksToMarkdown(raw[layoutField]);
|
||||
const desc = pickDescription(raw);
|
||||
const parts = [
|
||||
`## ${title}`
|
||||
];
|
||||
if (path) {
|
||||
parts.push(`${origin}${path}`);
|
||||
}
|
||||
if (desc) {
|
||||
parts.push(`_${desc}_`);
|
||||
}
|
||||
if (body) {
|
||||
parts.push(body);
|
||||
}
|
||||
sections.push(parts.join('\n\n'));
|
||||
}
|
||||
if (sections.length > 0) {
|
||||
lines.push(sections.join('\n\n---\n\n'), '');
|
||||
}
|
||||
return lines.join('\n');
|
||||
}
|
||||
const pageLinks = [];
|
||||
for (const raw of result.docs){
|
||||
if (raw._status && raw._status !== 'published') {
|
||||
@@ -78,7 +129,8 @@ import { buildLocalizedPath } from '../i18n/index.js';
|
||||
if (!path) {
|
||||
continue;
|
||||
}
|
||||
const pageDesc = typeof raw.meta?.description === 'string' ? ` — ${raw.meta.description}` : '';
|
||||
const desc = pickDescription(raw);
|
||||
const pageDesc = desc ? ` — ${desc}` : '';
|
||||
pageLinks.push(`- [${title}](${origin}${path})${pageDesc}`);
|
||||
}
|
||||
if (pageLinks.length > 0) {
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+49
-8
@@ -1,4 +1,36 @@
|
||||
type RobotRule = {
|
||||
allow?: string;
|
||||
disallow?: string[];
|
||||
userAgent: string | string[];
|
||||
};
|
||||
/**
|
||||
* Known AI user agents, split by purpose:
|
||||
* - assistant/search bots fetch a page to answer a user's question live or to
|
||||
* power an AI search index — the ones that make "the chat reads your site"
|
||||
* work, and that most businesses WANT.
|
||||
* - training crawlers collect pages to train models — some clients prefer to
|
||||
* opt out of these while keeping assistant/search visibility.
|
||||
*/
|
||||
export declare const AI_ASSISTANT_BOTS: readonly ["ClaudeBot", "Claude-Web", "Claude-SearchBot", "ChatGPT-User", "OAI-SearchBot", "PerplexityBot", "Perplexity-User"];
|
||||
export declare const AI_TRAINING_BOTS: readonly ["GPTBot", "Google-Extended", "CCBot", "anthropic-ai", "Applebot-Extended", "Bytespider", "Meta-ExternalAgent"];
|
||||
type AiBotsPolicy = 'allow' | 'block-training' | 'disallow' | false;
|
||||
type BuildRobotsArgs = {
|
||||
/** Override the assistant/search bot list. */
|
||||
aiAssistantAgents?: readonly string[];
|
||||
/**
|
||||
* How to treat AI crawlers (assistant/search + training). Default 'allow' —
|
||||
* explicitly welcome them so the site stays visible to Claude, ChatGPT,
|
||||
* Perplexity etc. and an accidental future '*' tightening doesn't lock them
|
||||
* out. Options:
|
||||
* - 'allow' (default): explicit allow for assistant AND training bots.
|
||||
* - 'block-training': allow assistant/search bots, disallow training crawlers
|
||||
* — keep AI answers/visibility, opt out of model training.
|
||||
* - 'disallow': block all known AI bots.
|
||||
* - false: emit no AI-specific rules (only the '*' rule).
|
||||
*/
|
||||
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. */
|
||||
@@ -7,20 +39,18 @@ type BuildRobotsArgs = {
|
||||
sitemap?: boolean;
|
||||
};
|
||||
/**
|
||||
* Shape for Next's `app/robots.ts`.
|
||||
* 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.
|
||||
*/
|
||||
export type RobotsRules = {
|
||||
host?: string;
|
||||
rules: {
|
||||
allow?: string;
|
||||
disallow?: string[];
|
||||
userAgent: string;
|
||||
};
|
||||
rules: RobotRule | RobotRule[];
|
||||
sitemap?: string;
|
||||
};
|
||||
/**
|
||||
* Builds robots rules that allow crawling everything except the admin panel and
|
||||
* API, and point crawlers at the sitemap.
|
||||
* API, point crawlers at the sitemap, and (by default) explicitly welcome AI
|
||||
* assistant/search/training bots.
|
||||
*
|
||||
* ```ts
|
||||
* // app/robots.ts
|
||||
@@ -31,6 +61,17 @@ export type RobotsRules = {
|
||||
*
|
||||
* The admin and API are disallowed by default — no reason for them in the index,
|
||||
* and it keeps crawl budget on real content.
|
||||
*
|
||||
* AI visibility: the #1 reason "the chat won't read the site" is an AI user
|
||||
* agent being blocked (or not explicitly allowed under a tightened '*' rule).
|
||||
* `aiBots: 'allow'` (default) emits explicit allow rules for ClaudeBot, GPTBot,
|
||||
* 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:
|
||||
* ```ts
|
||||
* buildRobots({ baseUrl, disallow: ['/admin', '/api', '/*?meter=*', '/*?s=*'] })
|
||||
* ```
|
||||
*/
|
||||
export declare function buildRobots({ baseUrl, disallow, sitemap, }: BuildRobotsArgs): RobotsRules;
|
||||
export declare function buildRobots({ aiAssistantAgents, aiBots, aiTrainingAgents, baseUrl, disallow, sitemap, }: BuildRobotsArgs): RobotsRules;
|
||||
export {};
|
||||
|
||||
Vendored
+84
-6
@@ -1,6 +1,32 @@
|
||||
/**
|
||||
* Known AI user agents, split by purpose:
|
||||
* - assistant/search bots fetch a page to answer a user's question live or to
|
||||
* power an AI search index — the ones that make "the chat reads your site"
|
||||
* work, and that most businesses WANT.
|
||||
* - training crawlers collect pages to train models — some clients prefer to
|
||||
* opt out of these while keeping assistant/search visibility.
|
||||
*/ export const AI_ASSISTANT_BOTS = [
|
||||
'ClaudeBot',
|
||||
'Claude-Web',
|
||||
'Claude-SearchBot',
|
||||
'ChatGPT-User',
|
||||
'OAI-SearchBot',
|
||||
'PerplexityBot',
|
||||
'Perplexity-User'
|
||||
];
|
||||
export const AI_TRAINING_BOTS = [
|
||||
'GPTBot',
|
||||
'Google-Extended',
|
||||
'CCBot',
|
||||
'anthropic-ai',
|
||||
'Applebot-Extended',
|
||||
'Bytespider',
|
||||
'Meta-ExternalAgent'
|
||||
];
|
||||
/**
|
||||
* Builds robots rules that allow crawling everything except the admin panel and
|
||||
* API, and point crawlers at the sitemap.
|
||||
* API, point crawlers at the sitemap, and (by default) explicitly welcome AI
|
||||
* assistant/search/training bots.
|
||||
*
|
||||
* ```ts
|
||||
* // app/robots.ts
|
||||
@@ -11,17 +37,69 @@
|
||||
*
|
||||
* The admin and API are disallowed by default — no reason for them in the index,
|
||||
* and it keeps crawl budget on real content.
|
||||
*/ export function buildRobots({ baseUrl, disallow = [
|
||||
*
|
||||
* AI visibility: the #1 reason "the chat won't read the site" is an AI user
|
||||
* agent being blocked (or not explicitly allowed under a tightened '*' rule).
|
||||
* `aiBots: 'allow'` (default) emits explicit allow rules for ClaudeBot, GPTBot,
|
||||
* 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:
|
||||
* ```ts
|
||||
* buildRobots({ baseUrl, disallow: ['/admin', '/api', '/*?meter=*', '/*?s=*'] })
|
||||
* ```
|
||||
*/ export function buildRobots({ aiAssistantAgents = AI_ASSISTANT_BOTS, aiBots = 'allow', aiTrainingAgents = AI_TRAINING_BOTS, baseUrl, disallow = [
|
||||
'/admin',
|
||||
'/api'
|
||||
], sitemap = true }) {
|
||||
const origin = baseUrl.replace(/\/$/, '');
|
||||
return {
|
||||
rules: {
|
||||
const baseRule = {
|
||||
allow: '/',
|
||||
disallow,
|
||||
userAgent: '*'
|
||||
};
|
||||
const aiRules = [];
|
||||
if (aiBots === 'allow') {
|
||||
aiRules.push({
|
||||
allow: '/',
|
||||
disallow,
|
||||
userAgent: '*'
|
||||
},
|
||||
userAgent: [
|
||||
...aiAssistantAgents,
|
||||
...aiTrainingAgents
|
||||
]
|
||||
});
|
||||
} else if (aiBots === 'block-training') {
|
||||
aiRules.push({
|
||||
allow: '/',
|
||||
disallow,
|
||||
userAgent: [
|
||||
...aiAssistantAgents
|
||||
]
|
||||
});
|
||||
aiRules.push({
|
||||
disallow: [
|
||||
'/'
|
||||
],
|
||||
userAgent: [
|
||||
...aiTrainingAgents
|
||||
]
|
||||
});
|
||||
} else if (aiBots === 'disallow') {
|
||||
aiRules.push({
|
||||
disallow: [
|
||||
'/'
|
||||
],
|
||||
userAgent: [
|
||||
...aiAssistantAgents,
|
||||
...aiTrainingAgents
|
||||
]
|
||||
});
|
||||
}
|
||||
return {
|
||||
rules: aiRules.length > 0 ? [
|
||||
baseRule,
|
||||
...aiRules
|
||||
] : baseRule,
|
||||
...sitemap ? {
|
||||
sitemap: `${origin}/sitemap.xml`
|
||||
} : {},
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+39
@@ -0,0 +1,39 @@
|
||||
type SpeakableJsonLdArgs = {
|
||||
/**
|
||||
* CSS selectors marking the parts best suited to be read aloud by voice
|
||||
* assistants / AI (a summary, the lead paragraph, key answer). Default
|
||||
* ['h1', '.speakable']. Keep it to genuinely readable, self-contained text —
|
||||
* not nav or boilerplate.
|
||||
*/
|
||||
cssSelectors?: string[];
|
||||
/** Optional @id to join this node into a @graph (e.g. `${url}#webpage`). */
|
||||
id?: string;
|
||||
/** Canonical URL of the page this describes. */
|
||||
url: string;
|
||||
};
|
||||
/**
|
||||
* Builds WebPage JSON-LD with a `speakable` SpeakableSpecification — tells voice
|
||||
* assistants and AI which parts of the page are meant to be read aloud /
|
||||
* quoted. A GEO signal: pairs with the Markdown/llms work to make the page's key
|
||||
* content easy for assistants to lift cleanly.
|
||||
*
|
||||
* Add to the page's @graph via JsonLdGraph (recommended) or emit standalone:
|
||||
*
|
||||
* import { buildSpeakableJsonLd } from '@intecion/ipal-kit'
|
||||
* const node = buildSpeakableJsonLd({ url: canonical, cssSelectors: ['h1', '.lead'] })
|
||||
*
|
||||
* Mark the matching elements in the project markup (e.g. className="speakable"
|
||||
* or a `.lead` summary). Selectors that match nothing are simply ignored by
|
||||
* consumers — but don't point at nav/boilerplate.
|
||||
*/
|
||||
export declare function buildSpeakableJsonLd({ id, cssSelectors, url, }: SpeakableJsonLdArgs): {
|
||||
speakable: {
|
||||
'@type': string;
|
||||
cssSelector: string[];
|
||||
};
|
||||
url: string;
|
||||
'@id'?: string | undefined;
|
||||
'@context': string;
|
||||
'@type': string;
|
||||
};
|
||||
export {};
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Builds WebPage JSON-LD with a `speakable` SpeakableSpecification — tells voice
|
||||
* assistants and AI which parts of the page are meant to be read aloud /
|
||||
* quoted. A GEO signal: pairs with the Markdown/llms work to make the page's key
|
||||
* content easy for assistants to lift cleanly.
|
||||
*
|
||||
* Add to the page's @graph via JsonLdGraph (recommended) or emit standalone:
|
||||
*
|
||||
* import { buildSpeakableJsonLd } from '@intecion/ipal-kit'
|
||||
* const node = buildSpeakableJsonLd({ url: canonical, cssSelectors: ['h1', '.lead'] })
|
||||
*
|
||||
* Mark the matching elements in the project markup (e.g. className="speakable"
|
||||
* or a `.lead` summary). Selectors that match nothing are simply ignored by
|
||||
* consumers — but don't point at nav/boilerplate.
|
||||
*/ export function buildSpeakableJsonLd({ id, cssSelectors = [
|
||||
'h1',
|
||||
'.speakable'
|
||||
], url }) {
|
||||
return {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'WebPage',
|
||||
...id ? {
|
||||
'@id': id
|
||||
} : {},
|
||||
speakable: {
|
||||
'@type': 'SpeakableSpecification',
|
||||
cssSelector: cssSelectors
|
||||
},
|
||||
url
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=buildSpeakableJsonLd.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/modules/seo/buildSpeakableJsonLd.ts"],"sourcesContent":["type SpeakableJsonLdArgs = {\n /**\n * CSS selectors marking the parts best suited to be read aloud by voice\n * assistants / AI (a summary, the lead paragraph, key answer). Default\n * ['h1', '.speakable']. Keep it to genuinely readable, self-contained text —\n * not nav or boilerplate.\n */\n cssSelectors?: string[]\n /** Optional @id to join this node into a @graph (e.g. `${url}#webpage`). */\n id?: string\n /** Canonical URL of the page this describes. */\n url: string\n}\n\n/**\n * Builds WebPage JSON-LD with a `speakable` SpeakableSpecification — tells voice\n * assistants and AI which parts of the page are meant to be read aloud /\n * quoted. A GEO signal: pairs with the Markdown/llms work to make the page's key\n * content easy for assistants to lift cleanly.\n *\n * Add to the page's @graph via JsonLdGraph (recommended) or emit standalone:\n *\n * import { buildSpeakableJsonLd } from '@intecion/ipal-kit'\n * const node = buildSpeakableJsonLd({ url: canonical, cssSelectors: ['h1', '.lead'] })\n *\n * Mark the matching elements in the project markup (e.g. className=\"speakable\"\n * or a `.lead` summary). Selectors that match nothing are simply ignored by\n * consumers — but don't point at nav/boilerplate.\n */\nexport function buildSpeakableJsonLd({\n id,\n cssSelectors = ['h1', '.speakable'],\n url,\n}: SpeakableJsonLdArgs) {\n return {\n '@context': 'https://schema.org',\n '@type': 'WebPage',\n ...(id ? { '@id': id } : {}),\n speakable: {\n '@type': 'SpeakableSpecification',\n cssSelector: cssSelectors,\n },\n url,\n }\n}\n"],"names":["buildSpeakableJsonLd","id","cssSelectors","url","speakable","cssSelector"],"mappings":"AAcA;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASA,qBAAqB,EACnCC,EAAE,EACFC,eAAe;IAAC;IAAM;CAAa,EACnCC,GAAG,EACiB;IACpB,OAAO;QACL,YAAY;QACZ,SAAS;QACT,GAAIF,KAAK;YAAE,OAAOA;QAAG,IAAI,CAAC,CAAC;QAC3BG,WAAW;YACT,SAAS;YACTC,aAAaH;QACf;QACAC;IACF;AACF"}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
import type { Field, TextareaField } from 'payload';
|
||||
type BuildSummaryFieldArgs = {
|
||||
/** Auto-fill from page content when the editor leaves it empty. Default true. */
|
||||
autoFill?: boolean;
|
||||
/** Help text under the field. */
|
||||
description?: string;
|
||||
/** Sidebar/admin label. */
|
||||
label?: string;
|
||||
/** Block layout field to derive the summary from. Default 'layout'. */
|
||||
layoutField?: string;
|
||||
/** Target length for the auto-generated summary. Default 300. */
|
||||
maxLength?: number;
|
||||
/** Field name. Default 'aiSummary'. */
|
||||
name?: string;
|
||||
/** Extend/override the generated textarea (position, access…). */
|
||||
overrides?: Partial<TextareaField>;
|
||||
};
|
||||
/**
|
||||
* A localized `aiSummary` textarea — a concise, human-written (or auto-derived)
|
||||
* description of the page, richer than the SEO meta description. It's the
|
||||
* preferred description for AI-facing surfaces: pass `summaryField: 'aiSummary'`
|
||||
* to buildLlmsTxt and searchContent and they'll use it over meta.description.
|
||||
*
|
||||
* With `autoFill` (default), an empty summary is filled on save from the page's
|
||||
* own content (blocks → plain text, trimmed to ~maxLength). Editors can always
|
||||
* overwrite it — auto-fill only runs when the field is blank, never clobbers a
|
||||
* manual summary. Derived from the page's OWN content, so no hard-coded data.
|
||||
*
|
||||
* // collections/Pages.ts
|
||||
* import { buildSummaryField } from '@intecion/ipal-kit'
|
||||
* fields: [ /* … *\/ buildSummaryField() ]
|
||||
*
|
||||
* // then, richer AI descriptions:
|
||||
* buildLlmsTxt({ …, summaryField: 'aiSummary' })
|
||||
* createSearchRoute({ …, summaryField: 'aiSummary' })
|
||||
*/
|
||||
export declare function buildSummaryField(args?: BuildSummaryFieldArgs): Field;
|
||||
export {};
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
import { blocksToMarkdown } from '../content/blocksToMarkdown.js';
|
||||
/** Rough Markdown → plain text, enough for a summary (drops syntax, keeps words). */ function mdToPlain(md) {
|
||||
return md.replace(/!\[[^\]]*\]\([^)]*\)/g, '') // images
|
||||
.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1') // links → their text
|
||||
.replace(/^#{1,6}\s+/gm, '') // heading markers
|
||||
.replace(/^[>\-*]\s+/gm, '') // quote/list markers
|
||||
.replace(/[*_~`]/g, '') // inline emphasis/code marks
|
||||
.replace(/\s+/g, ' ').trim();
|
||||
}
|
||||
/** Truncate at a word boundary, adding an ellipsis when cut. */ function truncate(text, max) {
|
||||
if (text.length <= max) {
|
||||
return text;
|
||||
}
|
||||
const slice = text.slice(0, max);
|
||||
const lastSpace = slice.lastIndexOf(' ');
|
||||
return `${(lastSpace > max * 0.6 ? slice.slice(0, lastSpace) : slice).trimEnd()}…`;
|
||||
}
|
||||
/**
|
||||
* A localized `aiSummary` textarea — a concise, human-written (or auto-derived)
|
||||
* description of the page, richer than the SEO meta description. It's the
|
||||
* preferred description for AI-facing surfaces: pass `summaryField: 'aiSummary'`
|
||||
* to buildLlmsTxt and searchContent and they'll use it over meta.description.
|
||||
*
|
||||
* With `autoFill` (default), an empty summary is filled on save from the page's
|
||||
* own content (blocks → plain text, trimmed to ~maxLength). Editors can always
|
||||
* overwrite it — auto-fill only runs when the field is blank, never clobbers a
|
||||
* manual summary. Derived from the page's OWN content, so no hard-coded data.
|
||||
*
|
||||
* // collections/Pages.ts
|
||||
* import { buildSummaryField } from '@intecion/ipal-kit'
|
||||
* fields: [ /* … *\/ buildSummaryField() ]
|
||||
*
|
||||
* // then, richer AI descriptions:
|
||||
* buildLlmsTxt({ …, summaryField: 'aiSummary' })
|
||||
* createSearchRoute({ …, summaryField: 'aiSummary' })
|
||||
*/ export function buildSummaryField(args = {}) {
|
||||
const { name = 'aiSummary', autoFill = true, description = 'Zwięzły opis strony dla agentów AI i llms.txt (bogatszy niż meta description). Puste → generowane automatycznie z treści.', label = 'Streszczenie dla AI', layoutField = 'layout', maxLength = 300, overrides = {} } = args;
|
||||
const autofillHook = ({ data, value })=>{
|
||||
if (typeof value === 'string' && value.trim()) {
|
||||
return value;
|
||||
} // never clobber a manual summary
|
||||
if (!data || typeof data !== 'object') {
|
||||
return value;
|
||||
}
|
||||
const layout = data[layoutField];
|
||||
const md = blocksToMarkdown(layout);
|
||||
if (!md) {
|
||||
return value;
|
||||
}
|
||||
const plain = mdToPlain(md);
|
||||
return plain ? truncate(plain, maxLength) : value;
|
||||
};
|
||||
const { admin: adminOverrides, hooks: hooksOverrides, ...restOverrides } = overrides;
|
||||
return {
|
||||
name,
|
||||
type: 'textarea',
|
||||
admin: {
|
||||
description,
|
||||
position: 'sidebar',
|
||||
...adminOverrides
|
||||
},
|
||||
hooks: {
|
||||
...hooksOverrides,
|
||||
...autoFill ? {
|
||||
beforeChange: [
|
||||
autofillHook,
|
||||
...hooksOverrides?.beforeChange ?? []
|
||||
]
|
||||
} : {}
|
||||
},
|
||||
label,
|
||||
localized: true,
|
||||
...restOverrides
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=buildSummaryField.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
Vendored
+3
-1
@@ -11,13 +11,15 @@ export { buildMetadata } from './buildMetadata.js';
|
||||
export type { PageMetadata } from './buildMetadata.js';
|
||||
export { buildNoindexField } from './buildNoindexField.js';
|
||||
export { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js';
|
||||
export { buildRobots } from './buildRobots.js';
|
||||
export { AI_ASSISTANT_BOTS, AI_TRAINING_BOTS, buildRobots } from './buildRobots.js';
|
||||
export type { RobotsRules } from './buildRobots.js';
|
||||
export { buildServiceJsonLd } from './buildServiceJsonLd.js';
|
||||
export { buildSitemapEntries } from './buildSitemapEntries.js';
|
||||
export type { SitemapEntry } from './buildSitemapEntries.js';
|
||||
export { buildSitemapXml } from './buildSitemapXml.js';
|
||||
export { buildSiteNavigationJsonLd } from './buildSiteNavigationJsonLd.js';
|
||||
export { buildSpeakableJsonLd } from './buildSpeakableJsonLd.js';
|
||||
export { buildSummaryField } from './buildSummaryField.js';
|
||||
export { buildWebSiteJsonLd } from './buildWebSiteJsonLd.js';
|
||||
export { composeTitle } from './composeTitle.js';
|
||||
export type { TitleOrder } from './composeTitle.js';
|
||||
|
||||
Vendored
+3
-1
@@ -9,11 +9,13 @@ export { createManifestHandler } from './buildManifest.js';
|
||||
export { buildMetadata } from './buildMetadata.js';
|
||||
export { buildNoindexField } from './buildNoindexField.js';
|
||||
export { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js';
|
||||
export { buildRobots } from './buildRobots.js';
|
||||
export { AI_ASSISTANT_BOTS, AI_TRAINING_BOTS, buildRobots } from './buildRobots.js';
|
||||
export { buildServiceJsonLd } from './buildServiceJsonLd.js';
|
||||
export { buildSitemapEntries } from './buildSitemapEntries.js';
|
||||
export { buildSitemapXml } from './buildSitemapXml.js';
|
||||
export { buildSiteNavigationJsonLd } from './buildSiteNavigationJsonLd.js';
|
||||
export { buildSpeakableJsonLd } from './buildSpeakableJsonLd.js';
|
||||
export { buildSummaryField } from './buildSummaryField.js';
|
||||
export { buildWebSiteJsonLd } from './buildWebSiteJsonLd.js';
|
||||
export { composeTitle } from './composeTitle.js';
|
||||
export { createMetadataGenerator } from './createMetadataGenerator.js';
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"sources":["../../../src/modules/seo/index.ts"],"sourcesContent":["export { buildAutoFillMetaHook } from './autoFillMeta.js'\nexport type { AutoFillMapping } from './autoFillMeta.js'\nexport { buildArticleJsonLd } from './buildArticleJsonLd.js'\nexport { buildBreadcrumbJsonLd } from './buildBreadcrumbJsonLd.js'\nexport { buildFaqJsonLd } from './buildFaqJsonLd.js'\nexport { buildIconsMetadata } from './buildIconsMetadata.js'\nexport { buildLlmsTxt } from './buildLlmsTxt.js'\nexport { buildLocalBusinessJsonLd } from './buildLocalBusinessJsonLd.js'\nexport { createManifestHandler } from './buildManifest.js'\nexport { buildMetadata } from './buildMetadata.js'\nexport type { PageMetadata } from './buildMetadata.js'\nexport { buildNoindexField } from './buildNoindexField.js'\nexport { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js'\nexport { buildRobots } from './buildRobots.js'\nexport type { RobotsRules } from './buildRobots.js'\nexport { buildServiceJsonLd } from './buildServiceJsonLd.js'\nexport { buildSitemapEntries } from './buildSitemapEntries.js'\nexport type { SitemapEntry } from './buildSitemapEntries.js'\nexport { buildSitemapXml } from './buildSitemapXml.js'\nexport { buildSiteNavigationJsonLd } from './buildSiteNavigationJsonLd.js'\nexport { buildWebSiteJsonLd } from './buildWebSiteJsonLd.js'\nexport { composeTitle } from './composeTitle.js'\nexport type { TitleOrder } from './composeTitle.js'\nexport { createMetadataGenerator } from './createMetadataGenerator.js'\nexport { createPageMetadata } from './createPageMetadata.js'\nexport { buildHreflangAlternates } from './hreflang.js'\nexport { injectAutoFillMeta } from './injectAutoFillMeta.js'\nexport { injectSeoTabs } from './injectSeoTabs.js'\nexport { JsonLdGraph } from './JsonLdGraph.js'\nexport { readSiteMetaConfig } from './readSiteMetaConfig.js'\nexport type { SiteMetaConfig } from './readSiteMetaConfig.js'\nexport { createLlmsTxtRoute, createSitemapRouteHandler } from './routeHandlers.js'\nexport { buildSeoPlugin } from './seoPluginConfig.js'\nexport { slugsAcrossLocales } from './slugsAcrossLocales.js'\nexport type { SeoMeta, SeoOption } from './types.js'\nexport { validateFaviconField } from './validateFavicon.js'\n"],"names":["buildAutoFillMetaHook","buildArticleJsonLd","buildBreadcrumbJsonLd","buildFaqJsonLd","buildIconsMetadata","buildLlmsTxt","buildLocalBusinessJsonLd","createManifestHandler","buildMetadata","buildNoindexField","buildOrganizationJsonLd","buildRobots","buildServiceJsonLd","buildSitemapEntries","buildSitemapXml","buildSiteNavigationJsonLd","buildWebSiteJsonLd","composeTitle","createMetadataGenerator","createPageMetadata","buildHreflangAlternates","injectAutoFillMeta","injectSeoTabs","JsonLdGraph","readSiteMetaConfig","createLlmsTxtRoute","createSitemapRouteHandler","buildSeoPlugin","slugsAcrossLocales","validateFaviconField"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,oBAAmB;AAEzD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,qBAAqB,QAAQ,6BAA4B;AAClE,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,wBAAwB,QAAQ,gCAA+B;AACxE,SAASC,qBAAqB,QAAQ,qBAAoB;AAC1D,SAASC,aAAa,QAAQ,qBAAoB;AAElD,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,mBAAmB,QAAQ,2BAA0B;AAE9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,yBAAyB,QAAQ,iCAAgC;AAC1E,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,uBAAuB,QAAQ,gBAAe;AACvD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,SAASC,kBAAkB,EAAEC,yBAAyB,QAAQ,qBAAoB;AAClF,SAASC,cAAc,QAAQ,uBAAsB;AACrD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,SAASC,oBAAoB,QAAQ,uBAAsB"}
|
||||
{"version":3,"sources":["../../../src/modules/seo/index.ts"],"sourcesContent":["export { buildAutoFillMetaHook } from './autoFillMeta.js'\nexport type { AutoFillMapping } from './autoFillMeta.js'\nexport { buildArticleJsonLd } from './buildArticleJsonLd.js'\nexport { buildBreadcrumbJsonLd } from './buildBreadcrumbJsonLd.js'\nexport { buildFaqJsonLd } from './buildFaqJsonLd.js'\nexport { buildIconsMetadata } from './buildIconsMetadata.js'\nexport { buildLlmsTxt } from './buildLlmsTxt.js'\nexport { buildLocalBusinessJsonLd } from './buildLocalBusinessJsonLd.js'\nexport { createManifestHandler } from './buildManifest.js'\nexport { buildMetadata } from './buildMetadata.js'\nexport type { PageMetadata } from './buildMetadata.js'\nexport { buildNoindexField } from './buildNoindexField.js'\nexport { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js'\nexport { AI_ASSISTANT_BOTS, AI_TRAINING_BOTS, buildRobots } from './buildRobots.js'\nexport type { RobotsRules } from './buildRobots.js'\nexport { buildServiceJsonLd } from './buildServiceJsonLd.js'\nexport { buildSitemapEntries } from './buildSitemapEntries.js'\nexport type { SitemapEntry } from './buildSitemapEntries.js'\nexport { buildSitemapXml } from './buildSitemapXml.js'\nexport { buildSiteNavigationJsonLd } from './buildSiteNavigationJsonLd.js'\nexport { buildSpeakableJsonLd } from './buildSpeakableJsonLd.js'\nexport { buildSummaryField } from './buildSummaryField.js'\nexport { buildWebSiteJsonLd } from './buildWebSiteJsonLd.js'\nexport { composeTitle } from './composeTitle.js'\nexport type { TitleOrder } from './composeTitle.js'\nexport { createMetadataGenerator } from './createMetadataGenerator.js'\nexport { createPageMetadata } from './createPageMetadata.js'\nexport { buildHreflangAlternates } from './hreflang.js'\nexport { injectAutoFillMeta } from './injectAutoFillMeta.js'\nexport { injectSeoTabs } from './injectSeoTabs.js'\nexport { JsonLdGraph } from './JsonLdGraph.js'\nexport { readSiteMetaConfig } from './readSiteMetaConfig.js'\nexport type { SiteMetaConfig } from './readSiteMetaConfig.js'\nexport { createLlmsTxtRoute, createSitemapRouteHandler } from './routeHandlers.js'\nexport { buildSeoPlugin } from './seoPluginConfig.js'\nexport { slugsAcrossLocales } from './slugsAcrossLocales.js'\nexport type { SeoMeta, SeoOption } from './types.js'\nexport { validateFaviconField } from './validateFavicon.js'\n"],"names":["buildAutoFillMetaHook","buildArticleJsonLd","buildBreadcrumbJsonLd","buildFaqJsonLd","buildIconsMetadata","buildLlmsTxt","buildLocalBusinessJsonLd","createManifestHandler","buildMetadata","buildNoindexField","buildOrganizationJsonLd","AI_ASSISTANT_BOTS","AI_TRAINING_BOTS","buildRobots","buildServiceJsonLd","buildSitemapEntries","buildSitemapXml","buildSiteNavigationJsonLd","buildSpeakableJsonLd","buildSummaryField","buildWebSiteJsonLd","composeTitle","createMetadataGenerator","createPageMetadata","buildHreflangAlternates","injectAutoFillMeta","injectSeoTabs","JsonLdGraph","readSiteMetaConfig","createLlmsTxtRoute","createSitemapRouteHandler","buildSeoPlugin","slugsAcrossLocales","validateFaviconField"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,oBAAmB;AAEzD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,qBAAqB,QAAQ,6BAA4B;AAClE,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,wBAAwB,QAAQ,gCAA+B;AACxE,SAASC,qBAAqB,QAAQ,qBAAoB;AAC1D,SAASC,aAAa,QAAQ,qBAAoB;AAElD,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,iBAAiB,EAAEC,gBAAgB,EAAEC,WAAW,QAAQ,mBAAkB;AAEnF,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,mBAAmB,QAAQ,2BAA0B;AAE9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,yBAAyB,QAAQ,iCAAgC;AAC1E,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,uBAAuB,QAAQ,gBAAe;AACvD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,SAASC,kBAAkB,EAAEC,yBAAyB,QAAQ,qBAAoB;AAClF,SAASC,cAAc,QAAQ,uBAAsB;AACrD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,SAASC,oBAAoB,QAAQ,uBAAsB"}
|
||||
Vendored
+10
@@ -13,13 +13,23 @@ import type { SitemapEntry } from './buildSitemapEntries.js';
|
||||
* export const dynamic = 'force-dynamic'
|
||||
* export const GET = createLlmsTxtRoute({ getCachedPayload, config: i18nConfig,
|
||||
* baseUrl: process.env.NEXT_PUBLIC_SERVER_URL! })
|
||||
*
|
||||
* For the full-content variant, add a second route with `full: true`:
|
||||
*
|
||||
* // app/llms-full.txt/route.ts
|
||||
* export const GET = createLlmsTxtRoute({ getCachedPayload, config: i18nConfig,
|
||||
* baseUrl: process.env.NEXT_PUBLIC_SERVER_URL!, full: true })
|
||||
*/
|
||||
export declare function createLlmsTxtRoute(opts: {
|
||||
baseUrl: string;
|
||||
config: I18nConfig;
|
||||
/** Inline every page's full Markdown (llms-full.txt). Default false. */
|
||||
full?: boolean;
|
||||
getCachedPayload: () => Promise<BasePayload>;
|
||||
pagesSlug?: string;
|
||||
settingsSlug?: string;
|
||||
/** Field holding a richer AI summary (buildSummaryField) to prefer as description. */
|
||||
summaryField?: string;
|
||||
}): () => Promise<Response>;
|
||||
/**
|
||||
* Ready-made Next route handler for /sitemap.xml with the CSS stylesheet.
|
||||
|
||||
Vendored
+9
-1
@@ -12,6 +12,12 @@ import { buildSitemapXml } from './buildSitemapXml.js';
|
||||
* export const dynamic = 'force-dynamic'
|
||||
* export const GET = createLlmsTxtRoute({ getCachedPayload, config: i18nConfig,
|
||||
* baseUrl: process.env.NEXT_PUBLIC_SERVER_URL! })
|
||||
*
|
||||
* For the full-content variant, add a second route with `full: true`:
|
||||
*
|
||||
* // app/llms-full.txt/route.ts
|
||||
* export const GET = createLlmsTxtRoute({ getCachedPayload, config: i18nConfig,
|
||||
* baseUrl: process.env.NEXT_PUBLIC_SERVER_URL!, full: true })
|
||||
*/ export function createLlmsTxtRoute(opts) {
|
||||
return async ()=>{
|
||||
try {
|
||||
@@ -19,9 +25,11 @@ import { buildSitemapXml } from './buildSitemapXml.js';
|
||||
const body = await buildLlmsTxt({
|
||||
baseUrl: opts.baseUrl,
|
||||
config: opts.config,
|
||||
full: opts.full,
|
||||
pagesSlug: opts.pagesSlug,
|
||||
payload,
|
||||
settingsSlug: opts.settingsSlug
|
||||
settingsSlug: opts.settingsSlug,
|
||||
summaryField: opts.summaryField
|
||||
});
|
||||
return new Response(body, {
|
||||
headers: {
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user