Files
blog-frontend-v2/src/lib/markdoc.server.ts

22 lines
515 B
TypeScript

import './server-only.ts'
import { renderMarkdocTree } from './markdoc.ts'
import { generateCacheKey, markdocCache } from './markdoc-cache.server.ts'
export const getCachedMarkdocTree = async (content: string) => {
if (!import.meta.env.SSR) {
return await renderMarkdocTree(content)
}
const key = generateCacheKey(content)
const cached = await markdocCache.get(key)
if (cached) {
return cached
}
const tree = await renderMarkdocTree(content)
markdocCache.set(key, tree)
return tree
}