Skip to content

Commit f3a8c97

Browse files
authored
[codex] enable markdown negotiation for agents (#133)
* enable markdown negotiation for agents * address markdown negotiation review comments * fix inline markdown code fences
1 parent 74998fd commit f3a8c97

7 files changed

Lines changed: 976 additions & 0 deletions

File tree

‎functions/_middleware.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import runtime from "../src/markdown-negotiation-runtime.cjs";
2+
3+
const { negotiateMarkdownResponse } = runtime;
4+
5+
export async function onRequest(context) {
6+
const { env, next, request } = context;
7+
const response = await next();
8+
9+
return negotiateMarkdownResponse({
10+
assetsFetch: env.ASSETS.fetch.bind(env.ASSETS),
11+
request,
12+
response,
13+
});
14+
}

‎package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
"devDependencies": {
4545
"@docusaurus/module-type-aliases": "2.4.1",
4646
"@tsconfig/docusaurus": "^1.0.5",
47+
"domutils": "^3.0.1",
48+
"htmlparser2": "^8.0.1",
4749
"typescript": "^4.7.4",
4850
"wrangler": "^4.42.0"
4951
},

‎plugins/llms-txt-plugin.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
const fs = require('fs');
1414
const path = require('path');
15+
const { exportMarkdownFiles } = require('../src/build-markdown.cjs');
1516

1617
const BASE_URL = 'https://api-docs.quran.foundation';
1718

@@ -238,6 +239,14 @@ function llmsTxtPlugin(context) {
238239
console.log(
239240
`[llms-txt-plugin] Generated ${outFile} with ${linkCount} links`,
240241
);
242+
243+
// 3. Emit markdown siblings for every generated HTML page so Cloudflare
244+
// Pages middleware can negotiate `Accept: text/markdown` without
245+
// changing the default HTML experience for browsers.
246+
const exportedCount = exportMarkdownFiles(outDir);
247+
console.log(
248+
`[llms-txt-plugin] Generated ${exportedCount} markdown page variants`,
249+
);
241250
},
242251
};
243252
}

0 commit comments

Comments
 (0)