mirror of
https://github.com/imfing/hextra.git
synced 2025-05-14 12:17:06 -04:00
Compare commits
5 Commits
aa60cf3580
...
48d82dffbd
Author | SHA1 | Date | |
---|---|---|---|
![]() |
48d82dffbd | ||
![]() |
bd34a5bad3 | ||
![]() |
da56d153aa | ||
![]() |
5c0698c3c0 | ||
![]() |
ebdaf0fd4a |
@ -31,6 +31,8 @@
|
|||||||
{{- range .Site.Menus.main -}}
|
{{- range .Site.Menus.main -}}
|
||||||
{{- if eq .Params.type "search" -}}
|
{{- if eq .Params.type "search" -}}
|
||||||
{{- partial "search.html" (dict "params" .Params) -}}
|
{{- partial "search.html" (dict "params" .Params) -}}
|
||||||
|
{{- else if eq .Params.type "theme-toggle" -}}
|
||||||
|
{{- partial "theme-toggle.html" (dict "navbar" true "hideLabel" (.Params.hideLabel | default true)) -}}
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
{{- $link := .URL -}}
|
{{- $link := .URL -}}
|
||||||
{{- $external := strings.HasPrefix $link "http" -}}
|
{{- $external := strings.HasPrefix $link "http" -}}
|
||||||
|
@ -37,9 +37,32 @@
|
|||||||
{{- $mermaidJS := resources.Get "lib/mermaid/mermaid.min.js" | fingerprint -}}
|
{{- $mermaidJS := resources.Get "lib/mermaid/mermaid.min.js" | fingerprint -}}
|
||||||
<script defer src="{{ $mermaidJS.RelPermalink }}" integrity="{{ $mermaidJS.Data.Integrity }}"></script>
|
<script defer src="{{ $mermaidJS.RelPermalink }}" integrity="{{ $mermaidJS.Data.Integrity }}"></script>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
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";
|
const theme = document.documentElement.classList.contains("dark") ? "dark" : "default";
|
||||||
mermaid.initialize({ startOnLoad: true, theme: theme });
|
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>
|
</script>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
{{- $navbar := .navbar | default false -}}
|
||||||
|
{{- $height_px := 12 -}}
|
||||||
|
{{- $height_tw := "hx-text-xs" -}}
|
||||||
|
{{- if $navbar -}}
|
||||||
|
{{- $height_px = 24 -}}
|
||||||
|
{{- $height_tw = "hx-text-sm" -}}
|
||||||
|
{{- end -}}
|
||||||
{{- $hideLabel := .hideLabel | default false -}}
|
{{- $hideLabel := .hideLabel | default false -}}
|
||||||
|
|
||||||
{{- $changeTheme := (T "changeTheme") | default "Change theme" -}}
|
{{- $changeTheme := (T "changeTheme") | default "Change theme" -}}
|
||||||
@ -8,14 +15,14 @@
|
|||||||
<button
|
<button
|
||||||
title="{{ $changeTheme }}"
|
title="{{ $changeTheme }}"
|
||||||
data-theme="light"
|
data-theme="light"
|
||||||
class="theme-toggle hx-group hx-h-7 hx-rounded-md hx-px-2 hx-text-left hx-text-xs hx-font-medium hx-text-gray-600 hx-transition-colors dark:hx-text-gray-400 hover:hx-bg-gray-100 hover:hx-text-gray-900 dark:hover:hx-bg-primary-100/5 dark:hover:hx-text-gray-50"
|
class="theme-toggle hx-group hx-h-7 hx-rounded-md hx-px-2 hx-text-left {{ $height_tw }} hx-font-medium hx-text-gray-600 hx-transition-colors dark:hx-text-gray-400 hover:hx-bg-gray-100 hover:hx-text-gray-900 dark:hover:hx-bg-primary-100/5 dark:hover:hx-text-gray-50"
|
||||||
type="button"
|
type="button"
|
||||||
aria-label="{{ $changeTheme }}"
|
aria-label="{{ $changeTheme }}"
|
||||||
>
|
>
|
||||||
<div class="hx-flex hx-items-center hx-gap-2 hx-capitalize">
|
<div class="hx-flex hx-items-center hx-gap-2 hx-capitalize">
|
||||||
{{- partial "utils/icon.html" (dict "name" "sun" "attributes" "height=12 class=\"group-data-[theme=light]:hx-hidden\"") -}}
|
{{- partial "utils/icon.html" (dict "name" "sun" "attributes" (printf "height=%d class=\"group-data-[theme=light]:hx-hidden\"" $height_px)) -}}
|
||||||
{{- if not $hideLabel }}<span class="group-data-[theme=light]:hx-hidden">{{ $light }}</span>{{ end -}}
|
{{- if not $hideLabel }}<span class="group-data-[theme=light]:hx-hidden">{{ $light }}</span>{{ end -}}
|
||||||
{{- partial "utils/icon.html" (dict "name" "moon" "attributes" "height=12 class=\"group-data-[theme=dark]:hx-hidden\"") -}}
|
{{- partial "utils/icon.html" (dict "name" "moon" "attributes" (printf "height=%d class=\"group-data-[theme=dark]:hx-hidden\"" $height_px)) -}}
|
||||||
{{- if not $hideLabel }}<span class="group-data-[theme=dark]:hx-hidden">{{ $dark }}</span>{{ end -}}
|
{{- if not $hideLabel }}<span class="group-data-[theme=dark]:hx-hidden">{{ $dark }}</span>{{ end -}}
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user