diff --git a/next.config.mjs b/next.config.mjs index b1afe62b..7557be47 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -33,6 +33,8 @@ const config = { source: '/blog/:path*.md', destination: '/llms.md/blog/:path*', }, + // The blog index twin (CORE-690 follow-up, 13/11/2026). + { source: '/blog.md', destination: '/llms.md/blog' }, // affitor.com/changelog (14/10/2026): the index twin and one twin per entry. { source: '/changelog.md', destination: '/llms.md/changelog' }, { source: '/changelog/:slug.md', destination: '/llms.md/changelog/:slug' }, diff --git a/scripts/check-agent-surface.mjs b/scripts/check-agent-surface.mjs index 877cd667..25cbee62 100644 --- a/scripts/check-agent-surface.mjs +++ b/scripts/check-agent-surface.mjs @@ -205,9 +205,50 @@ function inventory() { updated: data.updated ?? data.date, sourceDate: data.updated ?? data.date, body: markdown(data, id), + date: data.date, category: data.category, title: data.title, description: data.description, }; }); - return [...docs, ...posts, ...changelogInventory()]; + return [...docs, blogIndexInventory(posts), ...posts, ...changelogInventory()]; +} + +// Mirror of BLOG_DESCRIPTION in src/lib/blog.ts. +const BLOG_DESCRIPTION = 'Essays, launches, and guides from the team building Affitor — affiliate infrastructure for the agent era.'; + +/** + * affitor.com/blog and its twin /blog.md (CORE-690 follow-up, 13/11/2026): one line per post, newest first and then + * by slug, so same-day posts keep one order on the page, in its JSON-LD and in the twin. Dated by the newest post. + * Mirror of blogIndex() and sortedPosts() in src/lib/blog.ts and src/lib/agent-md.ts. + */ +function blogIndexInventory(posts) { + const listed = [...posts].sort((a, b) => b.date.localeCompare(a.date) || a.id.localeCompare(b.id)); + const updated = posts.map((post) => post.updated).sort().at(-1); + const lines = listed.map((post) => `- ${post.date} · ${post.category} · [${post.title}](${post.url}): ${post.description}`); + return { + id: 'blog', type: 'blog', url: `${ORIGIN}/blog`, updated, sourceDate: updated, listed, + body: `# Affitor Blog\n\n> ${BLOG_DESCRIPTION}\n\n## Posts\n\n${lines.join('\n')}\n`, + }; +} + +/** The built /blog page: the twin link, and one CollectionPage whose ItemList is the twin's list, in order. */ +function checkBlogIndexHtml(index) { + const html = read(join(APP, 'blog.html')); + const links = [...html.matchAll(/]*>/g)].map((match) => match[0]) + .filter((tag) => /\brel="alternate"/.test(tag) && /\btype="text\/markdown"/.test(tag)); + assert.equal(links.length, 1, '/blog: expected one text/markdown alternate link'); + assert.equal(new URL(decodeEntities(links[0].match(/\bhref="([^"]*)"/)[1]), ORIGIN).href, `${ORIGIN}/blog.md`, '/blog: twin link'); + const schemas = [...html.matchAll(/]*\btype="application\/ld\+json"[^>]*>([\s\S]*?)<\/script>/g)] + .map((match) => JSON.parse(match[1])).filter((schema) => schema['@type'] === 'CollectionPage'); + assert.equal(schemas.length, 1, '/blog: expected one CollectionPage'); + const [schema] = schemas; + assert.equal(schema['@id'], index.url, '/blog: CollectionPage @id'); + assert.equal(schema.description, BLOG_DESCRIPTION, '/blog: CollectionPage description'); + assert.equal(schema.mainEntity?.['@type'], 'ItemList', '/blog: CollectionPage mainEntity'); + assert.equal(schema.mainEntity.numberOfItems, index.listed.length, '/blog: ItemList size'); + assert.deepEqual( + schema.mainEntity.itemListElement.map((item) => [item.position, item.url, item.name]), + index.listed.map((post, i) => [i + 1, post.url, post.title]), + '/blog: ItemList differs from the twin list', + ); } /** @@ -549,8 +590,8 @@ function main() { }; }); const expectedUrls = pages.flatMap((page) => [page.url, markdownUrl(page)]); - // The blog index has no twin; it is listed once, dated by the newest post (CORE-690). - expectedUrls.push(`${ORIGIN}/blog`, `${SITE}/llms.txt`, `${SITE}/llms-full.txt`); + // The blog index is a page with a twin since 13/11/2026 (CORE-690 follow-up), dated by the newest post. + expectedUrls.push(`${SITE}/llms.txt`, `${SITE}/llms-full.txt`); assert.deepEqual(entries.map((entry) => entry.url).sort(), expectedUrls.sort(), 'Sitemap URL inventory differs from source'); const dates = new Map(entries.map((entry) => [entry.url, entry.lastmod])); const datedPages = pages.filter((page) => page.updated); @@ -599,7 +640,8 @@ function main() { assert.equal(corpus.indexOf(twin, position + twin.length), -1, `${page.id}: duplicate twin in llms-full.txt`); corpus = corpus.slice(0, position) + corpus.slice(position + twin.length); if (page.type === 'doc') checkHtml(page, new URL(page.url).pathname); - console.log(`PASS ${page.id}: twin, source body, sitemap dates, full corpus${page.type === 'doc' ? ', HTML and canonical' : ''}`); + if (page.id === 'blog') checkBlogIndexHtml(page); + console.log(`PASS ${page.id}: twin, source body, sitemap dates, full corpus${page.type === 'doc' ? ', HTML and canonical' : page.id === 'blog' ? ', twin link and CollectionPage' : ''}`); } assert.match(corpus, /^\n*$/, 'llms-full.txt contains unexpected content or extra pages'); diff --git a/scripts/check-docs-host-http.mjs b/scripts/check-docs-host-http.mjs index 16302baa..165d827a 100644 --- a/scripts/check-docs-host-http.mjs +++ b/scripts/check-docs-host-http.mjs @@ -65,6 +65,8 @@ const ALWAYS = [ [PROXY, '/changelog/invite-partners', 200, null, 'text/html'], [PROXY, '/changelog.md', 200, null, 'text/markdown'], [PROXY, '/changelog/invite-partners.md', 200, null, 'text/markdown'], + // The blog index twin (13/11/2026), which affitor.com/blog.md proxies to. + [PROXY, '/blog.md', 200, null, 'text/markdown'], [PROXY, '/changelog/rss.xml', 200, null, 'application/rss+xml'], [PROXY, '/changelog.json', 200, null, 'application/json'], [PROXY, '/changelog/context.md', 200, null, 'text/markdown'], @@ -150,7 +152,8 @@ const ALWAYS = [ [PROXY, '/changelog/invite-partners', 200, null, 'text/html', HTML], [PROXY, '/changelog', 200, null, 'text/markdown', MD], [PROXY, '/changelog', 200, null, 'text/html', HTML], - [PROXY, '/blog', 200, null, 'text/html', NO_TWIN], + [PROXY, '/blog', 200, null, 'text/markdown', MD], + [PROXY, '/blog', 200, null, 'text/html', HTML], [PROXY, '/docs/api/search?query=payout', 200, null, 'application/json', NO_TWIN], [PROXY, '/changelog/rss.xml', 200, null, 'application/rss+xml', NO_TWIN], [PROXY, '/docs/brand/quickstart.md', 200, null, 'text/markdown', NO_TWIN], diff --git a/scripts/check-docs-host.mjs b/scripts/check-docs-host.mjs index 26ad1896..ea38a0a6 100644 --- a/scripts/check-docs-host.mjs +++ b/scripts/check-docs-host.mjs @@ -266,6 +266,8 @@ function invariants() { ['/docs', '/docs/index.md'], ['/docs/api-reference/errors', '/docs/api-reference/errors.md'], ['/blog/rewardful-alternatives', '/blog/rewardful-alternatives.md'], + // The blog index has its twin since the blog index twin change (13/11/2026), like the changelog index. + ['/blog', '/blog.md'], ['/changelog', '/changelog.md'], ['/changelog?for=brands', '/changelog.md?for=brands'], ['/changelog/invite-partners', '/changelog/invite-partners.md'], @@ -273,8 +275,8 @@ function invariants() { for (const path of [ // Not pages: no twin, even where a .md answers (/changelog/context.md is the AI context pack). '/docs/no-such-page', '/docs/brand/no-such-page', '/blog/no-such-post', '/changelog/no-such-entry', '/changelog/context', - '/blog', '/docs/api/search', '/docs/openapi.json', '/docs/llms-full.txt', '/docs/brand/quickstart.md', '/docs/skill.md', - '/docs/brand/dashboard.png', '/blog/rewardful-alternatives.md', '/blog/covers/x.png', '/changelog.md', '/changelog/invite-partners.md', + '/docs/api/search', '/docs/openapi.json', '/docs/llms-full.txt', '/docs/brand/quickstart.md', '/docs/skill.md', + '/docs/brand/dashboard.png', '/blog.md', '/blog/rewardful-alternatives.md', '/blog/covers/x.png', '/changelog.md', '/changelog/invite-partners.md', '/changelog/rss.xml', '/changelog.json', '/changelog/context.md', '/docsy', '/brand/quickstart', ]) check(`${host}${path} has no twin: Accept: text/markdown changes nothing`, untouched(host, path)); // Redirects run before negotiation: the client negotiates again at the new URL. @@ -395,14 +397,13 @@ mode('yes', () => { }); delete process.env.DOCS_HOST_REDIRECT; -check('twin list: docs index, changelog index, every blog post and changelog entry, no twin paths', () => { +check('twin list: docs index, blog index, changelog index, every blog post and changelog entry, no twin paths', () => { const slugs = (dir) => readdirSync(join(ROOT, dir)).filter((f) => f.endsWith('.mdx')).map((f) => f.slice(0, -4)); - for (const path of ['/docs', '/docs/brand/quickstart', '/changelog', ...slugs('content/blog').map((s) => `/blog/${s}`), ...slugs('content/changelog').map((s) => `/changelog/${s}`)]) { + for (const path of ['/docs', '/docs/brand/quickstart', '/blog', '/changelog', ...slugs('content/blog').map((s) => `/blog/${s}`), ...slugs('content/changelog').map((s) => `/changelog/${s}`)]) { assert.ok(TWIN_PAGES.includes(path), `${path} missing from src/generated/markdown-twins.json`); } for (const path of TWIN_PAGES) assert.match(path, /^\/(?:docs|blog|changelog)(?:\/[^.]+)?$/, `${path}: a page path, not a file`); assert.equal(TWIN_PAGES.includes('/changelog/context'), false); - assert.equal(TWIN_PAGES.includes('/blog'), false); }); check(`every listed page (${TWIN_PAGES.length}) negotiates on affitor.com`, () => { for (const path of TWIN_PAGES) { diff --git a/scripts/gen-llms.js b/scripts/gen-llms.js index 500bb282..bd7d3fcf 100644 --- a/scripts/gen-llms.js +++ b/scripts/gen-llms.js @@ -99,12 +99,14 @@ ${sections()} const mdxSlugs = (dir) => readdirSync(join(ROOT, dir)).filter((file) => file.endsWith('.mdx')).map((file) => file.slice(0, -4)); /** - * Page paths with a real .md twin (src/app/llms.md): docs pages, blog posts (content/blog), the - * changelog index and its entries (content/changelog/*.mdx). Sorted, so the file is deterministic. + * Page paths with a real .md twin (src/app/llms.md): docs pages, the blog index and its posts + * (content/blog), the changelog index and its entries (content/changelog/*.mdx). Sorted, so the file + * is deterministic. */ export function generateTwins() { const paths = [ ...docsSource().getPages().map((page) => page.url), + '/blog', ...mdxSlugs('content/blog').map((slug) => `/blog/${slug}`), '/changelog', ...mdxSlugs('content/changelog').map((slug) => `/changelog/${slug}`), diff --git a/src/app/blog/page.tsx b/src/app/blog/page.tsx index 28ae5796..4efd9208 100644 --- a/src/app/blog/page.tsx +++ b/src/app/blog/page.tsx @@ -1,17 +1,16 @@ import type { Metadata } from 'next'; import Link from 'next/link'; -import { blog } from '@/../.source/server'; import { BlogShell } from '@/components/blog/blog-shell'; import { formatDate, postSlug } from '@/components/blog/post-meta'; -import { BLOG_URL } from '@/lib/site'; +import { BLOG_DESCRIPTION, sortedPosts, type Post } from '@/lib/blog'; +import { BLOG_URL, SITE_URL } from '@/lib/site'; export const metadata: Metadata = { // absolute: the blog lives on affitor.com, so no "| Affitor Docs" suffix. title: { absolute: 'Blog | Affitor' }, - description: - 'Essays, launches, and guides from the team building Affitor — affiliate infrastructure for the agent era.', - // Canonical home of the blog is the proxied affitor.com/blog zone. - alternates: { canonical: BLOG_URL }, + description: BLOG_DESCRIPTION, + // Canonical home of the blog is the proxied affitor.com/blog zone; /blog.md is its machine-readable twin. + alternates: { canonical: BLOG_URL, types: { 'text/markdown': '/blog.md' } }, openGraph: { title: 'Affitor Blog', description: @@ -27,10 +26,28 @@ export const metadata: Metadata = { }, }; -type Post = (typeof blog)[number]; - -function byDateDesc(a: Post, b: Post) { - return new Date(b.date).getTime() - new Date(a.date).getTime(); +/** CollectionPage of every post, in the page's order (same list as /blog.md); each post page has its own BlogPosting. */ +function jsonLd(posts: Post[]) { + return JSON.stringify({ + '@context': 'https://schema.org', + '@type': 'CollectionPage', + '@id': BLOG_URL, + url: BLOG_URL, + name: 'Affitor Blog', + description: BLOG_DESCRIPTION, + publisher: { '@type': 'Organization', name: 'Affitor', url: SITE_URL }, + mainEntity: { + '@type': 'ItemList', + itemListOrder: 'https://schema.org/ItemListOrderDescending', + numberOfItems: posts.length, + itemListElement: posts.map((post, i) => ({ + '@type': 'ListItem', + position: i + 1, + url: `${BLOG_URL}/${postSlug(post.info.path)}`, + name: post.title, + })), + }, + }).replace(/ + {/* eslint-disable-next-line react/no-danger -- server-rendered schema; `<` escaped */} +