Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/node/markdown/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ export interface MarkdownEnv {
relativePath: string
cleanUrls: boolean
links?: string[]
includes?: string[]
}
1 change: 1 addition & 0 deletions src/node/markdown/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface MarkdownOptions extends MarkdownIt.Options {
languages?: ILanguageRegistration[]
toc?: TocPluginOptions
externalLinks?: Record<string, string>
cache?: boolean
}

export type MarkdownRenderer = MarkdownIt
Expand Down
6 changes: 3 additions & 3 deletions src/node/markdown/plugins/snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
17 changes: 11 additions & 6 deletions src/node/markdownToVue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -125,7 +127,8 @@ export async function createMarkdownToVueRenderFn(
const env: MarkdownEnv = {
path: file,
relativePath,
cleanUrls
cleanUrls,
includes
}
const html = md.render(src, env)
const {
Expand Down Expand Up @@ -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
}
}
Expand Down