hugo-theme-anubis2/layouts/partials/mermaid_support.html
2024-11-17 19:19:14 +08:00

25 lines
972 B
HTML

{{ partial "resource.html" (dict "context" . "type" "js" "filename" "js/load-mermaid.js") }}
{{ $colorTheme := "light" }}
{{ if and (site.Params.colortheme) (ne site.Params.colortheme "") }}
{{ $colorTheme = site.Params.colortheme | lower }}
{{ end }}
<script type="module">
function detectCurrentScheme3() {
const defaultTheme = "{{ $colorTheme }}";
if (localStorage !== null && localStorage.getItem("user-color-scheme")) {
return localStorage.getItem("user-color-scheme");
}
if (defaultTheme === "dark" || defaultTheme === "light") {
return defaultTheme;
}
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
}
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
window.mermaid = mermaid;
window.initMermaid()
document.body.dispatchEvent(new CustomEvent(detectCurrentScheme3() + "-theme-set"));
</script>