Skip to content

Commit 3553f01

Browse files
authored
fix: make md includes work with rewrites (#1898)
BREAKING CHANGES: Markdown includes are now resolved relative to original file path instead of rewritten one.
1 parent 3991170 commit 3553f01

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/node/markdownToVue.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ export async function createMarkdownToVueRenderFn(
5555
file: string,
5656
publicDir: string
5757
): Promise<MarkdownCompileResult> => {
58+
const fileOrig = file
5859
const alias =
5960
siteConfig?.rewrites.map[file] || // virtual dynamic path file
6061
siteConfig?.rewrites.map[file.slice(srcDir.length + 1)]
6162
file = alias ? path.join(srcDir, alias) : file
6263
const relativePath = slash(path.relative(srcDir, file))
63-
const dir = path.dirname(file)
6464
const cacheKey = JSON.stringify({ src, file })
6565

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

0 commit comments

Comments
 (0)