From 8ee38115f2b0755cdb8251a1e29980db99d88cfd Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 9 Jun 2026 13:52:29 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20try=20rendering=20`/index.md/index.html`?= =?UTF-8?q?=20=F0=9F=A4=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/md-rewrite.ts | 13 +++++-------- nuxt.config.ts | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/modules/md-rewrite.ts b/modules/md-rewrite.ts index c928b569..f3cc189e 100644 --- a/modules/md-rewrite.ts +++ b/modules/md-rewrite.ts @@ -18,21 +18,18 @@ export default defineNuxtModule({ const vcJSON = resolve(nitro.options.output.dir, 'config.json') const vcConfig = JSON.parse(await readFile(vcJSON, 'utf8')) - // Redirect Accept: text/markdown requests to the .md - // version. A redirect gives the markdown response its own URL and - // therefore its own edge cache key, so a markdown-accepting client - // can't poison the HTML cache entry for the bare URL. + // Rewrite requests with Accept: text/markdown to the .md version // The home page needs special handling: / -> /index.md vcConfig.routes.unshift({ src: '^/$', - status: 302, - headers: { Location: '/index.md' }, + dest: '/index.md', has: [{ type: 'header', key: 'accept', value: '(.*)text/markdown(.*)' }], + check: true, }, { src: '^/(.+?)/?$', - status: 302, - headers: { Location: '/$1.md' }, + dest: '/$1.md', has: [{ type: 'header', key: 'accept', value: '(.*)text/markdown(.*)' }], + check: true, }) await writeFile(vcJSON, JSON.stringify(vcConfig, null, 2), 'utf8') diff --git a/nuxt.config.ts b/nuxt.config.ts index 0b013dac..878ed10a 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -210,7 +210,7 @@ export default defineNuxtConfig({ }, hooks: { 'prerender:generate' (route) { - if (route.fileName) + if (route.fileName && route.route !== '/index.md') route.fileName = route.fileName.replace( /(\.\w{2,3})\/index.html$/, '$1', -- 2.54.0