Skip to content

Commit b00198b

Browse files
committed
fix: load mermaid as normal now that inline is safely below bundle size
1 parent 9e3e711 commit b00198b

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

quartz/components/renderPage.tsx

-14
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import { visit } from "unist-util-visit"
99
import { Root, Element, ElementContent } from "hast"
1010
import { GlobalConfiguration } from "../cfg"
1111
import { i18n } from "../i18n"
12-
// @ts-ignore
13-
import mermaidScript from "./scripts/mermaid.inline"
14-
import mermaidStyle from "./styles/mermaid.inline.scss"
1512
import { QuartzPluginData } from "../plugins/vfile"
1613

1714
interface RenderComponents {
@@ -65,17 +62,6 @@ export function pageResources(
6562
contentType: "external",
6663
})
6764

68-
// dynamic afterDOMReady must come after postscript.js
69-
if (fileData.hasMermaidDiagram) {
70-
resources.js.push({
71-
script: mermaidScript,
72-
loadTime: "afterDOMReady",
73-
moduleType: "module",
74-
contentType: "inline",
75-
})
76-
resources.css.push({ content: mermaidStyle, inline: true })
77-
}
78-
7965
return resources
8066
}
8167

quartz/components/scripts/mermaid.inline.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { removeAllChildren } from "./util"
1+
import { registerEscapeHandler, removeAllChildren } from "./util"
22

33
interface Position {
44
x: number
@@ -158,7 +158,7 @@ document.addEventListener("nav", async () => {
158158
)
159159

160160
mermaidImport ||= await import(
161-
//@ts-ignore
161+
// @ts-ignore
162162
"https://cdnjs.cloudflare.com/ajax/libs/mermaid/11.4.0/mermaid.esm.min.mjs"
163163
)
164164
const mermaid = mermaidImport.default
@@ -237,12 +237,12 @@ document.addEventListener("nav", async () => {
237237

238238
closeBtn.addEventListener("click", hideMermaid)
239239
expandBtn.addEventListener("click", showMermaid)
240+
registerEscapeHandler(popupContainer, hideMermaid)
240241
document.addEventListener("keydown", handleEscape)
241242

242243
window.addCleanup(() => {
243244
closeBtn.removeEventListener("click", hideMermaid)
244245
expandBtn.removeEventListener("click", showMermaid)
245-
document.removeEventListener("keydown", handleEscape)
246246
})
247247
}
248248
})

quartz/plugins/transformers/ofm.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ import path from "path"
1616
import { splitAnchor } from "../../util/path"
1717
import { JSResource, CSSResource } from "../../util/resources"
1818
// @ts-ignore
19-
import calloutScript from "../../components/scripts/callout.inline.ts"
19+
import calloutScript from "../../components/scripts/callout.inline"
2020
// @ts-ignore
21-
import checkboxScript from "../../components/scripts/checkbox.inline.ts"
21+
import checkboxScript from "../../components/scripts/checkbox.inline"
22+
// @ts-ignore
23+
import mermaidScript from "../../components/scripts/mermaid.inline"
24+
import mermaidStyle from "../../components/styles/mermaid.inline.scss"
2225
import { FilePath, pathToRoot, slugTag, slugifyFilePath } from "../../util/path"
2326
import { toHast } from "mdast-util-to-hast"
2427
import { toHtml } from "hast-util-to-html"
@@ -806,6 +809,20 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
806809
})
807810
}
808811

812+
if (opts.mermaid) {
813+
js.push({
814+
script: mermaidScript,
815+
loadTime: "afterDOMReady",
816+
contentType: "inline",
817+
moduleType: "module",
818+
})
819+
820+
css.push({
821+
content: mermaidStyle,
822+
inline: true,
823+
})
824+
}
825+
809826
return { js, css }
810827
},
811828
}

0 commit comments

Comments
 (0)