Skip to content

Commit 024d58b

Browse files
committed
Render Markdown if we get an Accept text/markdown header
1 parent ad2d7ef commit 024d58b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/middleware/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export const onRequest = defineMiddleware(async (context, next) => {
1414
"accept-encoding": "identity",
1515
},
1616
});
17-
} else if (pathname.endsWith("/index.md")) {
17+
} else if (
18+
pathname.endsWith("/index.md") ||
19+
context.request.headers.get("accept")?.includes("text/markdown")
20+
) {
1821
const htmlUrl = new URL(pathname.replace("index.md", ""), context.url);
1922
const html = await (await fetch(htmlUrl)).text();
2023

worker/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export default class extends WorkerEntrypoint<Env> {
3333
});
3434
}
3535

36-
if (request.url.endsWith("/index.md")) {
36+
if (
37+
request.url.endsWith("/index.md") ||
38+
request.headers.get("accept")?.includes("text/markdown")
39+
) {
3740
const htmlUrl = request.url.replace("index.md", "");
3841
const res = await this.env.ASSETS.fetch(htmlUrl, request);
3942

0 commit comments

Comments
 (0)