mirror of
https://github.com/thegeeklab/hugo-geekblog.git
synced 2024-11-21 20:50:40 +00:00
fix: use selector loop to manually render all charts on a page (#488)
This commit is contained in:
parent
785adf091b
commit
57afb60b99
3
package-lock.json
generated
3
package-lock.json
generated
@ -25,7 +25,7 @@
|
||||
"eslint-plugin-prettier": "5.1.3",
|
||||
"favicons": "7.1.5",
|
||||
"favicons-webpack-plugin": "6.0.1",
|
||||
"html-validate": "^8.9.1",
|
||||
"html-validate": "8.9.1",
|
||||
"npm-run-all": "4.1.5",
|
||||
"postcss-loader": "7.3.4",
|
||||
"prettier": "3.2.2",
|
||||
@ -34,6 +34,7 @@
|
||||
"shx": "0.3.4",
|
||||
"svg-sprite": "2.0.2",
|
||||
"svgtofont": "4.1.1",
|
||||
"uuid": "9.0.1",
|
||||
"webpack": "5.89.0",
|
||||
"webpack-cli": "5.1.4",
|
||||
"webpack-manifest-plugin": "5.0.0",
|
||||
|
@ -58,6 +58,7 @@
|
||||
"shx": "0.3.4",
|
||||
"svg-sprite": "2.0.2",
|
||||
"svgtofont": "4.1.1",
|
||||
"uuid": "9.0.1",
|
||||
"webpack": "5.89.0",
|
||||
"webpack-cli": "5.1.4",
|
||||
"webpack-manifest-plugin": "5.0.0",
|
||||
|
@ -1,30 +1,39 @@
|
||||
const Storage = require("store2")
|
||||
const { v4: uuidv4 } = require("uuid")
|
||||
const { COLOR_THEME_DARK, THEME, COLOR_THEME_AUTO } = require("./config.js")
|
||||
|
||||
import mermaid from "mermaid"
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function (event) {
|
||||
let lstore = Storage.namespace(THEME)
|
||||
let currentColorTheme = lstore.get("color-theme") || COLOR_THEME_AUTO
|
||||
let currentMode = lstore.get("color-theme") || COLOR_THEME_AUTO
|
||||
let darkModeQuery = window.matchMedia("(prefers-color-scheme: dark)")
|
||||
let darkMode = false
|
||||
let theme = "default"
|
||||
|
||||
if (
|
||||
currentColorTheme === COLOR_THEME_DARK ||
|
||||
(currentColorTheme === COLOR_THEME_AUTO && darkModeQuery.matches)
|
||||
currentMode === COLOR_THEME_DARK ||
|
||||
(currentMode === COLOR_THEME_AUTO && darkModeQuery.matches)
|
||||
) {
|
||||
darkMode = true
|
||||
theme = "dark"
|
||||
}
|
||||
|
||||
import("mermaid")
|
||||
.then(({ default: md }) => {
|
||||
md.initialize({
|
||||
flowchart: { useMaxWidth: true },
|
||||
theme: theme,
|
||||
themeVariables: {
|
||||
darkMode: darkMode
|
||||
}
|
||||
})
|
||||
mermaid.initialize({
|
||||
startOnLoad: false,
|
||||
flowchart: { useMaxWidth: true },
|
||||
theme: theme,
|
||||
themeVariables: {
|
||||
darkMode: darkMode
|
||||
}
|
||||
})
|
||||
|
||||
document.querySelectorAll(".mermaid").forEach(function (el) {
|
||||
let id = "graph-" + uuidv4()
|
||||
|
||||
mermaid.render(id, el.innerText).then(({ svg, bindFunctions }) => {
|
||||
el.innerHTML = svg
|
||||
bindFunctions?.(el)
|
||||
})
|
||||
.catch((error) => console.error(error))
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user