From 024d58b695edf39f8483b005a17f4e64d1ad78c0 Mon Sep 17 00:00:00 2001 From: Daniel Walsh Date: Mon, 29 Sep 2025 13:20:23 +0100 Subject: [PATCH] Render Markdown if we get an Accept text/markdown header --- src/middleware/index.ts | 5 ++++- worker/index.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/middleware/index.ts b/src/middleware/index.ts index 8f48dff6f28822..7e581b49c7c8b2 100644 --- a/src/middleware/index.ts +++ b/src/middleware/index.ts @@ -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(); diff --git a/worker/index.ts b/worker/index.ts index 78307d4a6a8124..0204e7c717a502 100644 --- a/worker/index.ts +++ b/worker/index.ts @@ -33,7 +33,10 @@ export default class extends WorkerEntrypoint { }); } - 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);