diff --git a/src/node/markdownToVue.ts b/src/node/markdownToVue.ts index 642dabd7..458837c0 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -57,21 +57,33 @@ export async function createMarkdownToVueRenderFn( base, siteConfig?.logger ) + pages = pages.map((p) => slash(p.replace(/\.md$/, ''))) + const dynamicRoutes = new Map( + siteConfig?.dynamicRoutes?.routes.map((r) => [ + r.fullPath, + path.join(srcDir, r.route) + ]) || [] + ) + + const rewrites = new Map( + Object.entries(siteConfig?.rewrites.map || {}).map(([key, value]) => [ + path.join(srcDir, key), + path.join(srcDir, value!) + ]) || [] + ) + return async ( src: string, file: string, publicDir: string ): Promise => { - const fileOrig = file - const alias = - siteConfig?.rewrites.map[file] || // virtual dynamic path file - siteConfig?.rewrites.map[file.slice(srcDir.length + 1)] - file = alias ? path.join(srcDir, alias) : file + const fileOrig = dynamicRoutes.get(file) || file + file = rewrites.get(file) || file const relativePath = slash(path.relative(srcDir, file)) - const cacheKey = JSON.stringify({ src, file: fileOrig }) + const cacheKey = JSON.stringify({ src, file: relativePath }) if (isBuild || options.cache !== false) { const cached = cache.get(cacheKey) if (cached) { diff --git a/src/node/plugin.ts b/src/node/plugin.ts index c91d9357..8132ad82 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -402,8 +402,9 @@ export async function createVitePressPlugin( config.publicDir ) + const relativePath = slash(path.relative(srcDir, file)) const payload: PageDataPayload = { - path: `/${slash(path.relative(srcDir, file))}`, + path: `/${siteConfig.rewrites.map[relativePath] || relativePath}`, pageData }