diff --git a/src/node/markdown/env.ts b/src/node/markdown/env.ts index b079c281..7ed29a31 100644 --- a/src/node/markdown/env.ts +++ b/src/node/markdown/env.ts @@ -36,4 +36,5 @@ export interface MarkdownEnv { relativePath: string cleanUrls: boolean links?: string[] + includes?: string[] } diff --git a/src/node/markdown/markdown.ts b/src/node/markdown/markdown.ts index 64de3b18..22298c8e 100644 --- a/src/node/markdown/markdown.ts +++ b/src/node/markdown/markdown.ts @@ -50,6 +50,7 @@ export interface MarkdownOptions extends MarkdownIt.Options { languages?: ILanguageRegistration[] toc?: TocPluginOptions externalLinks?: Record + cache?: boolean } export type MarkdownRenderer = MarkdownIt diff --git a/src/node/markdown/plugins/snippet.ts b/src/node/markdown/plugins/snippet.ts index 4efea38a..b558f35b 100644 --- a/src/node/markdown/plugins/snippet.ts +++ b/src/node/markdown/plugins/snippet.ts @@ -140,15 +140,15 @@ export const snippetPlugin = (md: MarkdownIt, srcDir: string) => { const fence = md.renderer.rules.fence! md.renderer.rules.fence = (...args) => { - const [tokens, idx, , { loader }] = args + const [tokens, idx, , { includes }] = args const token = tokens[idx] // @ts-ignore const [src, regionName] = token.src ?? [] if (!src) return fence(...args) - if (loader) { - loader.addDependency(src) + if (includes) { + includes.push(src) } const isAFile = fs.lstatSync(src).isFile() diff --git a/src/node/markdownToVue.ts b/src/node/markdownToVue.ts index 1629f2d8..483c3791 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -67,10 +67,12 @@ export async function createMarkdownToVueRenderFn( const relativePath = slash(path.relative(srcDir, file)) const cacheKey = JSON.stringify({ src, file }) - const cached = cache.get(cacheKey) - if (cached) { - debug(`[cache hit] ${relativePath}`) - return cached + if (isBuild || options.cache !== false) { + const cached = cache.get(cacheKey) + if (cached) { + debug(`[cache hit] ${relativePath}`) + return cached + } } const start = Date.now() @@ -125,7 +127,8 @@ export async function createMarkdownToVueRenderFn( const env: MarkdownEnv = { path: file, relativePath, - cleanUrls + cleanUrls, + includes } const html = md.render(src, env) const { @@ -243,7 +246,9 @@ export async function createMarkdownToVueRenderFn( deadLinks, includes } - cache.set(cacheKey, result) + if (isBuild || options.cache !== false) { + cache.set(cacheKey, result) + } return result } }