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:
+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
|
||||
Reference in New Issue
Block a user