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
97 lines
3.5 KiB
JavaScript
97 lines
3.5 KiB
JavaScript
import { blocksToMarkdown } from './blocksToMarkdown.js';
|
|
import { resolveRoute } from './resolveRoute.js';
|
|
function yamlEscape(v) {
|
|
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 = {}) {
|
|
const { collection = 'pages', content, frontmatter = true, layoutField = 'layout', overrides, settingsSlug = 'site-settings' } = args;
|
|
return async function render({ slug, locale, payload }) {
|
|
const route = await resolveRoute({
|
|
content,
|
|
locale,
|
|
pagesSlug: collection,
|
|
payload,
|
|
segments: slug,
|
|
settingsSlug
|
|
});
|
|
if (!route) {
|
|
return null;
|
|
}
|
|
const doc = route.doc;
|
|
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 = [];
|
|
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) {
|
|
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
|
|
});
|
|
}
|
|
|
|
//# sourceMappingURL=createMarkdownRenderer.js.map
|