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',