fix: hmr not updating page data in rewritten paths and file path is wrong in mdit for dynamic routes

closes #4172
pull/4177/head
Divyansh Singh 2 months ago
parent e6f9dd33c7
commit c46e4b784d

@ -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<MarkdownCompileResult> => {
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) {

@ -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
}

Loading…
Cancel
Save