fix: make md includes work with rewrites (#1898)

BREAKING CHANGES: Markdown includes are now resolved relative to original file path instead of rewritten one.
pull/2131/head
Christian Georgi 2 years ago committed by GitHub
parent 399117088b
commit 3553f015a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -55,12 +55,12 @@ export async function createMarkdownToVueRenderFn(
file: string, file: string,
publicDir: string publicDir: string
): Promise<MarkdownCompileResult> => { ): Promise<MarkdownCompileResult> => {
const fileOrig = file
const alias = const alias =
siteConfig?.rewrites.map[file] || // virtual dynamic path file siteConfig?.rewrites.map[file] || // virtual dynamic path file
siteConfig?.rewrites.map[file.slice(srcDir.length + 1)] siteConfig?.rewrites.map[file.slice(srcDir.length + 1)]
file = alias ? path.join(srcDir, alias) : file file = alias ? path.join(srcDir, alias) : file
const relativePath = slash(path.relative(srcDir, file)) const relativePath = slash(path.relative(srcDir, file))
const dir = path.dirname(file)
const cacheKey = JSON.stringify({ src, file }) const cacheKey = JSON.stringify({ src, file })
const cached = cache.get(cacheKey) const cached = cache.get(cacheKey)
@ -85,6 +85,7 @@ export async function createMarkdownToVueRenderFn(
let includes: string[] = [] let includes: string[] = []
src = src.replace(includesRE, (m, m1) => { src = src.replace(includesRE, (m, m1) => {
try { try {
const dir = path.dirname(fileOrig) // include paths are strict relative file paths w/o aliases
const includePath = path.join(dir, m1) const includePath = path.join(dir, m1)
const content = fs.readFileSync(includePath, 'utf-8') const content = fs.readFileSync(includePath, 'utf-8')
includes.push(slash(includePath)) includes.push(slash(includePath))

Loading…
Cancel
Save