添加博客渲染缓存
This commit is contained in:
@ -12,6 +12,15 @@ export const markdocConfig: Config = {
|
||||
highlightedHtml: { type: String },
|
||||
},
|
||||
transform(node, config) {
|
||||
/*
|
||||
* 注意力!!!!!!!!!!!!!!
|
||||
* 注意!!!!!!!!!!!!
|
||||
*
|
||||
* 如果改了这里的逻辑,记得更改 `markdoc-cache.ts` 里的版本号
|
||||
* 以让对应的缓存能够被更新
|
||||
*
|
||||
**/
|
||||
|
||||
const attributes = node.transformAttributes(config)
|
||||
|
||||
const highlightedHtml = shikiRender(
|
||||
@ -29,8 +38,28 @@ export const markdocConfig: Config = {
|
||||
},
|
||||
}
|
||||
|
||||
export const toMarkdocTree = async (content: string) => {
|
||||
const _toMarkdocTree = async (content: string) => {
|
||||
const ast = Markdoc.parse(content)
|
||||
await ensureShikiEngine()
|
||||
return Markdoc.transform(ast, markdocConfig)
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user