Skip to content

Commit

Permalink
fix: hmr not updating page data in rewritten paths and file path is w…
Browse files Browse the repository at this point in the history
…rong in mdit for dynamic routes

closes #4172
  • Loading branch information
brc-dd committed Sep 1, 2024
1 parent e6f9dd3 commit c46e4b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
24 changes: 18 additions & 6 deletions src/node/markdownToVue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit c46e4b7

Please sign in to comment.