Render Markdown if we get an Accept text/markdown header (#25493)

This commit is contained in:
Daniel Walsh 2025-09-29 14:11:52 +01:00 committed by GitHub
parent b7b0a21aab
commit fa1b1e26f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View file

@ -14,7 +14,10 @@ export const onRequest = defineMiddleware(async (context, next) => {
"accept-encoding": "identity",
},
});
} else if (pathname.endsWith("/index.md")) {
} else if (
pathname.endsWith("/index.md") ||
context.request.headers.get("accept")?.includes("text/markdown")
) {
const htmlUrl = new URL(pathname.replace("index.md", ""), context.url);
const html = await (await fetch(htmlUrl)).text();

View file

@ -33,7 +33,10 @@ export default class extends WorkerEntrypoint<Env> {
});
}
if (request.url.endsWith("/index.md")) {
if (
request.url.endsWith("/index.md") ||
request.headers.get("accept")?.includes("text/markdown")
) {
const htmlUrl = request.url.replace("index.md", "");
const res = await this.env.ASSETS.fetch(htmlUrl, request);