添加服务端运行警告

This commit is contained in:
2026-04-09 15:46:54 +08:00
parent 2de3841f7d
commit cd689aba98
7 changed files with 43 additions and 24 deletions

View File

@ -38,28 +38,10 @@ export const markdocConfig: Config = {
},
}
const _toMarkdocTree = async (content: string) => {
export const renderMarkdocTree = async (content: string) => {
const ast = Markdoc.parse(content)
await ensureShikiEngine()
const tree = Markdoc.transform(ast, markdocConfig)
return tree
}
export const toMarkdocTree = async (content: string) => {
if (!import.meta.env.SSR) {
return await _toMarkdocTree(content)
}
const cacheLib = await import('./markdoc-cache.ts')
const key = cacheLib.generateCacheKey(content)
const cached = await cacheLib.markdocCache.get(key)
if (cached) {
return cached
}
const tree = await _toMarkdocTree(content)
cacheLib.markdocCache.set(key, tree)
return tree
}