mirror of
https://github.com/imfing/hextra.git
synced 2025-06-20 08:01:21 -04:00
chore: adapt theme to new template system (#696)
* Adapted theme's layout to [Hugo v0.146.0](https://gohugo.io/templates/new-templatesystem-overview/) * Bumped minimal Hugo version to v0.146.0
This commit is contained in:
44
layouts/_partials/scripts/mermaid.html
Normal file
44
layouts/_partials/scripts/mermaid.html
Normal file
@ -0,0 +1,44 @@
|
||||
{{/* Mermaid */}}
|
||||
|
||||
{{ $mermaidJsUrl := printf "https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid%s.js" (cond hugo.IsProduction ".min" "") -}}
|
||||
{{ with try (resources.GetRemote $mermaidJsUrl) -}}
|
||||
{{ with .Err -}}
|
||||
{{ errorf "Could not retrieve Mermaid js file from %s. Reason: %s." $mermaidJsUrl . -}}
|
||||
{{ else with.Value -}}
|
||||
{{ with resources.Copy (printf "js/mermaid.min.js") . -}}
|
||||
{{ $mermaidJs := . | fingerprint -}}
|
||||
<script defer src="{{ $mermaidJs.RelPermalink }}" integrity="{{ $mermaidJs.Data.Integrity }}" crossorigin="anonymous"></script>
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
// Store original mermaid code for each diagram
|
||||
document.querySelectorAll(".mermaid").forEach((el) => {
|
||||
el.dataset.original = el.innerHTML;
|
||||
});
|
||||
|
||||
const theme = document.documentElement.classList.contains("dark") ? "dark" : "default";
|
||||
mermaid.initialize({ startOnLoad: true, theme: theme });
|
||||
|
||||
let timeout;
|
||||
new MutationObserver(() => {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
const theme = document.documentElement.classList.contains("dark") ? "dark" : "default";
|
||||
document.querySelectorAll(".mermaid").forEach((el) => {
|
||||
// Reset to original content, preserving HTML
|
||||
el.innerHTML = el.dataset.original;
|
||||
el.removeAttribute("data-processed");
|
||||
});
|
||||
mermaid.initialize({ startOnLoad: true, theme: theme });
|
||||
mermaid.init();
|
||||
}, 150);
|
||||
}).observe(document.documentElement, {
|
||||
attributes: true,
|
||||
attributeFilter: ["class"],
|
||||
});
|
||||
});
|
||||
</script>
|
Reference in New Issue
Block a user