Skip to content

Commit 6d7422f

Browse files
committed
fix: respect markdown.cache = false on build too
1 parent f386c1a commit 6d7422f

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

src/node/markdownToVue.ts

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ function getResolutionCache(siteConfig: SiteConfig) {
8383
export async function createMarkdownToVueRenderFn(
8484
srcDir: string,
8585
options: MarkdownOptions = {},
86-
isBuild = false,
8786
base = '/',
8887
includeLastUpdatedData = false,
8988
cleanUrls = false,
@@ -115,7 +114,7 @@ export async function createMarkdownToVueRenderFn(
115114
const relativePath = slash(path.relative(srcDir, file))
116115

117116
const cacheKey = JSON.stringify({ src, ts, relativePath })
118-
if (isBuild || options.cache !== false) {
117+
if (options.cache !== false) {
119118
const cached = cache.get(cacheKey)
120119
if (cached) {
121120
debug(`[cache hit] ${relativePath}`)
@@ -177,15 +176,9 @@ export async function createMarkdownToVueRenderFn(
177176
}
178177

179178
return siteConfig.ignoreDeadLinks.some((ignore) => {
180-
if (typeof ignore === 'string') {
181-
return url === ignore
182-
}
183-
if (ignore instanceof RegExp) {
184-
return ignore.test(url)
185-
}
186-
if (typeof ignore === 'function') {
187-
return ignore(url, fileOrig)
188-
}
179+
if (typeof ignore === 'string') return url === ignore
180+
if (ignore instanceof RegExp) return ignore.test(url)
181+
if (typeof ignore === 'function') return ignore(url, fileOrig)
189182
return false
190183
})
191184
}
@@ -198,6 +191,7 @@ export async function createMarkdownToVueRenderFn(
198191

199192
url = url.replace(/[?#].*$/, '').replace(/\.(html|md)$/, '')
200193
if (url.endsWith('/')) url += `index`
194+
201195
let resolved = decodeURIComponent(
202196
slash(
203197
url.startsWith('/')
@@ -207,6 +201,7 @@ export async function createMarkdownToVueRenderFn(
207201
)
208202
resolved =
209203
siteConfig?.rewrites.inv[resolved + '.md']?.slice(0, -3) || resolved
204+
210205
if (
211206
!pages.includes(resolved) &&
212207
!fs.existsSync(path.resolve(dir, publicDir, `${resolved}.html`)) &&
@@ -239,12 +234,7 @@ export async function createMarkdownToVueRenderFn(
239234
for (const fn of transformPageData) {
240235
if (fn) {
241236
const dataToMerge = await fn(pageData, { siteConfig })
242-
if (dataToMerge) {
243-
pageData = {
244-
...pageData,
245-
...dataToMerge
246-
}
247-
}
237+
if (dataToMerge) pageData = { ...pageData, ...dataToMerge }
248238
}
249239
}
250240

@@ -260,15 +250,8 @@ export async function createMarkdownToVueRenderFn(
260250

261251
debug(`[render] ${file} in ${Date.now() - start}ms.`)
262252

263-
const result = {
264-
vueSrc,
265-
pageData,
266-
deadLinks,
267-
includes
268-
}
269-
if (isBuild || options.cache !== false) {
270-
cache.set(cacheKey, result)
271-
}
253+
const result = { vueSrc, pageData, deadLinks, includes }
254+
if (options.cache !== false) cache.set(cacheKey, result)
272255
return result
273256
}
274257
}

src/node/plugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ export async function createVitePressPlugin(
116116
markdownToVue = await createMarkdownToVueRenderFn(
117117
srcDir,
118118
markdown,
119-
config.command === 'build',
120119
config.base,
121120
lastUpdated,
122121
cleanUrls,

0 commit comments

Comments
 (0)