feat: add configurable header actions

This commit is contained in:
Erzbir
2026-08-21 22:48:31 +08:00
parent 673ba99ab6
commit 922dc6ced6
11 changed files with 143 additions and 30 deletions
+11 -1
View File
@@ -12,6 +12,10 @@
customCss: /*[[${theme.config.style.custom}]]*/ "",
messages: {
currentColorScheme: /*[[#{header.color_scheme.current}]]*/ "Current color scheme",
currentAppearance: /*[[#{header.appearance.current}]]*/ "Current appearance",
appearanceLight: /*[[#{header.appearance.light}]]*/ "Light",
appearanceDark: /*[[#{header.appearance.dark}]]*/ "Dark",
appearanceSystem: /*[[#{header.appearance.system}]]*/ "System",
showToc: /*[[#{toc.show}]]*/ "Show table of contents",
hideToc: /*[[#{toc.hide}]]*/ "Hide table of contents",
networkError: /*[[#{moment.network_error}]]*/ "Network error. Please try again."
@@ -87,12 +91,18 @@
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
}
function normalizeThemeMode(mode) {
return ["light", "dark", "system"].includes(mode) ? mode : "system";
}
function applyTheme(mode, options = {}) {
if (options.clearColorScheme) {
removeStoredPreference(storageKeys.colorScheme);
}
const actualMode = mode === "system" ? getSystemScheme() : mode;
const normalizedMode = normalizeThemeMode(mode);
const actualMode = normalizedMode === "system" ? getSystemScheme() : normalizedMode;
root.dataset.themeMode = normalizedMode;
root.dataset.colorScheme = actualMode;
root.dataset.themeColorScheme = getStoredColorScheme() || resolveTheme(actualMode);
}