Skip to content

Commit

Permalink
fix: make md includes work with rewrites (#1898)
Browse files Browse the repository at this point in the history
BREAKING CHANGES: Markdown includes are now resolved relative to original file path instead of rewritten one.
  • Loading branch information
chgeo committed Mar 24, 2023
1 parent 3991170 commit 3553f01
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/node/markdownToVue.ts
Expand Up @@ -55,12 +55,12 @@ export async function createMarkdownToVueRenderFn(
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 relativePath = slash(path.relative(srcDir, file))
const dir = path.dirname(file)
const cacheKey = JSON.stringify({ src, file })

const cached = cache.get(cacheKey)
Expand All @@ -85,6 +85,7 @@ export async function createMarkdownToVueRenderFn(
let includes: string[] = []
src = src.replace(includesRE, (m, m1) => {
try {
const dir = path.dirname(fileOrig) // include paths are strict relative file paths w/o aliases
const includePath = path.join(dir, m1)
const content = fs.readFileSync(includePath, 'utf-8')
includes.push(slash(includePath))
Expand Down

0 comments on commit 3553f01

Please sign in to comment.