mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-12 22:14:08 +00:00
BREAKING CHANGE Module paths moved to `github.com/HugoBlox/kit` with new names: - core `blox-tailwind` → `blox` - analytics → `analytics` - netlify → `integrations/netlify` - slides (reveal) → `slides` Update go.mod, module.yaml/params, scripts, tests, and v0.11 migration guide accordingly.
46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
// Hugo Blox JS Global Init (CSP-friendly)
|
|
export function initTheme() {
|
|
const root = document.documentElement;
|
|
const defaultTheme = root.dataset.wcThemeDefault;
|
|
const setDark = () => {
|
|
root.classList.add("dark");
|
|
root.style.colorScheme = "dark";
|
|
};
|
|
const setLight = () => {
|
|
root.classList.remove("dark");
|
|
root.style.colorScheme = "light";
|
|
};
|
|
|
|
if ("wc-color-theme" in localStorage) {
|
|
localStorage.getItem("wc-color-theme") === "dark" ? setDark() : setLight();
|
|
} else {
|
|
if (defaultTheme === "dark") setDark();
|
|
else if (defaultTheme === "light") setLight();
|
|
else if (defaultTheme === "system") {
|
|
window.matchMedia("(prefers-color-scheme: dark)").matches ? setDark() : setLight();
|
|
}
|
|
}
|
|
}
|
|
|
|
export function applyHugoStyleFixes() {
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
const checkboxes = document.querySelectorAll("li input[type='checkbox'][disabled]");
|
|
checkboxes.forEach((e) => {
|
|
const parent = e.parentElement?.parentElement;
|
|
if (parent) parent.classList.add("task-list");
|
|
});
|
|
|
|
const liNodes = document.querySelectorAll(".task-list li");
|
|
liNodes.forEach((nodes) => {
|
|
const textNodes = Array.from(nodes.childNodes).filter((node) => node.nodeType === 3 && node.textContent && node.textContent.trim().length > 1);
|
|
if (textNodes.length > 0) {
|
|
const span = document.createElement("label");
|
|
textNodes[0].after(span);
|
|
const input = nodes.querySelector("input[type='checkbox']");
|
|
if (input) span.appendChild(input);
|
|
span.appendChild(textNodes[0]);
|
|
}
|
|
});
|
|
});
|
|
}
|