mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-23 03:56:23 +00:00
perf: don't load mermaid if its not on the page
This commit is contained in:
parent
bec726b666
commit
34334eabed
1 changed files with 15 additions and 10 deletions
|
@ -600,17 +600,22 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>
|
||||||
if (opts.mermaid) {
|
if (opts.mermaid) {
|
||||||
js.push({
|
js.push({
|
||||||
script: `
|
script: `
|
||||||
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
|
let mermaidImport = undefined
|
||||||
const darkMode = document.documentElement.getAttribute('saved-theme') === 'dark'
|
|
||||||
mermaid.initialize({
|
|
||||||
startOnLoad: false,
|
|
||||||
securityLevel: 'loose',
|
|
||||||
theme: darkMode ? 'dark' : 'default'
|
|
||||||
});
|
|
||||||
document.addEventListener('nav', async () => {
|
document.addEventListener('nav', async () => {
|
||||||
await mermaid.run({
|
if (document.querySelector("code.mermaid")) {
|
||||||
querySelector: '.mermaid'
|
mermaidImport ||= await import('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs')
|
||||||
})
|
const mermaid = mermaidImport.default
|
||||||
|
const darkMode = document.documentElement.getAttribute('saved-theme') === 'dark'
|
||||||
|
mermaid.initialize({
|
||||||
|
startOnLoad: false,
|
||||||
|
securityLevel: 'loose',
|
||||||
|
theme: darkMode ? 'dark' : 'default'
|
||||||
|
})
|
||||||
|
|
||||||
|
await mermaid.run({
|
||||||
|
querySelector: '.mermaid'
|
||||||
|
})
|
||||||
|
}
|
||||||
});
|
});
|
||||||
`,
|
`,
|
||||||
loadTime: "afterDOMReady",
|
loadTime: "afterDOMReady",
|
||||||
|
|
Loading…
Reference in a new issue