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:
2026-10-10 16:52:16 +02:00
parent e6eada5d39
commit 09925e4cfd
75 changed files with 3067 additions and 45 deletions
@@ -0,0 +1,123 @@
import type { BasePayload } from 'payload'
import type { ContentOption } from './types.js'
import { blocksToMarkdown } from './blocksToMarkdown.js'
import { resolveRoute } from './resolveRoute.js'
type CreateMarkdownRendererArgs = {
/** Pages collection. Default 'pages'. */
collection?: string
/** Archive-backed collections, same value as the plugin option (optional). */
content?: ContentOption
/** Prepend a YAML frontmatter block (title/description/locale). Default true. */
frontmatter?: boolean
/** Field holding the block layout. Default 'layout'. */
layoutField?: string
/** Per-blockType overrides passed to blocksToMarkdown. */
overrides?: Record<string, (block: Record<string, unknown>) => string>
/** SiteSettings global slug. Default 'site-settings'. */
settingsSlug?: string
}
type MarkdownContext = {
locale: string
payload: BasePayload
/** Route slug segments; empty/undefined = locale root (home). */
slug?: string[]
}
type DocShape = {
[key: string]: unknown
meta?: { description?: null | string } | null
title?: null | string
}
function yamlEscape(v: string): string {
return `"${v.replace(/"/g, '\\"')}"`
}
/**
* Returns a function that renders a page (or archive/entry) to clean Markdown —
* title, meta description, then the block layout via blocksToMarkdown. The
* point is AI-readability: an agent (Claude's WebFetch, GPT, Perplexity) gets
* structured Markdown instead of parsing HTML, so it reads the page reliably.
*
* Mirrors createPageMetadata: the plugin can't call getPayload, so it returns a
* function the project invokes from its route handler.
*
* // app/md/[locale]/[[...slug]]/route.ts (serves /md/pl/o-nas as text/markdown)
* import { createMarkdownRenderer, markdownResponse } from '@intecion/ipal-kit'
* import { getPayload } from 'payload'
* import config from '@payload-config'
* const render = createMarkdownRenderer({ content })
* export const dynamic = 'force-dynamic'
* export async function GET(_req: Request, { params }: { params: Promise<{ locale: string; slug?: string[] }> }) {
* const { locale, slug } = await params
* const md = await render({ payload: await getPayload({ config }), locale, slug })
* return markdownResponse(md)
* }
*
* Returns null when the route doesn't resolve (so the handler can 404).
*/
export function createMarkdownRenderer(args: CreateMarkdownRendererArgs = {}) {
const {
collection = 'pages',
content,
frontmatter = true,
layoutField = 'layout',
overrides,
settingsSlug = 'site-settings',
} = args
return async function render({ slug, locale, payload }: MarkdownContext): Promise<null | string> {
const route = await resolveRoute({
content,
locale,
pagesSlug: collection,
payload,
segments: slug,
settingsSlug,
})
if (!route) {return null}
const doc = route.doc as DocShape
const title = typeof doc.title === 'string' ? doc.title : ''
const description = typeof doc.meta?.description === 'string' ? doc.meta.description : ''
const body = blocksToMarkdown(doc[layoutField], { overrides })
const parts: string[] = []
if (frontmatter) {
const fm = ['---', `locale: ${locale}`]
if (title) {fm.push(`title: ${yamlEscape(title)}`)}
if (description) {fm.push(`description: ${yamlEscape(description)}`)}
fm.push('---')
parts.push(fm.join('\n'))
}
if (title) {parts.push(`# ${title}`)}
if (description) {parts.push(`_${description}_`)}
if (body) {parts.push(body)}
const md = parts.join('\n\n').trim()
return md || null
}
}
/**
* 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 {
if (md == null) {
return new Response('Not found', { headers: { 'content-type': 'text/plain' }, status: 404 })
}
return new Response(md, {
headers: {
'cache-control': 'public, max-age=0, s-maxage=3600, stale-while-revalidate=86400',
'content-type': 'text/markdown; charset=utf-8',
},
status: 200,
})
}