Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: fix https://github.com/siyuan-note/siyuan/issues/7259

Vanessab8c9511df58c
diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts
index edf26c87c7..aa6593d151 100644
--- a/app/src/protyle/export/index.ts
+++ b/app/src/protyle/export/index.ts
@@ -8,7 +8,7 @@ import * as path from "path";
import {afterExport} from "./util";
/// #endif
import {confirmDialog} from "../../dialog/confirmDialog";
-import {setInlineStyle} from "../../util/assets";
+import {getThemeMode, setInlineStyle} from "../../util/assets";
import {fetchPost} from "../../util/fetch";
import {Dialog} from "../../dialog";
import {lockFile} from "../../dialog/processSystem";
@@ -79,7 +79,8 @@ const renderPDF = (id: string) => {
if (!isDefault) {
themeStyle = `<link rel="stylesheet" type="text/css" id="themeStyle" href="${servePath}/appearance/themes/${window.siyuan.config.appearance.themeLight}/${window.siyuan.config.appearance.customCSS ? "custom" : "theme"}.css?${Constants.SIYUAN_VERSION}"/>`;
}
- const html = `<!DOCTYPE html><html>
+ const html = `<!DOCTYPE html>
+<html lang="${window.siyuan.config.appearance.lang}" data-theme-mode="${getThemeMode()}" data-light-theme="${window.siyuan.config.appearance.themeLight}" data-dark-theme="${window.siyuan.config.appearance.themeDark}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@@ -553,7 +554,8 @@ const onExport = (data: IWebSocketData, filePath: string, type: string, removeAs
if (!isDefault) {
themeStyle = `<link rel="stylesheet" type="text/css" id="themeStyle" href="appearance/themes/${themeName}/${window.siyuan.config.appearance.customCSS ? "custom" : "theme"}.css?${Constants.SIYUAN_VERSION}"/>`;
}
- const html = `<!DOCTYPE html><html>
+ const html = `<!DOCTYPE html>
+<html lang="${window.siyuan.config.appearance.lang}" data-theme-mode="${getThemeMode()}" data-light-theme="${window.siyuan.config.appearance.themeLight}" data-dark-theme="${window.siyuan.config.appearance.themeDark}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
diff --git a/app/src/util/assets.ts b/app/src/util/assets.ts
index 12b677e39f..dd471eeb53 100644
--- a/app/src/util/assets.ts
+++ b/app/src/util/assets.ts
@@ -22,6 +22,11 @@ const loadThirdIcon = (iconURL: string, data: IAppearance) => {
};
export const loadAssets = (data: IAppearance) => {
+ const htmlElement = document.getElementsByTagName("html")[0]
+ htmlElement.setAttribute("lang",window.siyuan.config.appearance.lang);
+ htmlElement.setAttribute("data-theme-mode",getThemeMode());
+ htmlElement.setAttribute("data-light-theme",window.siyuan.config.appearance.themeLight);
+ htmlElement.setAttribute("data-dark-theme",window.siyuan.config.appearance.themeDark);
const OSTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
if (window.siyuan.config.appearance.modeOS && (
(window.siyuan.config.appearance.mode === 1 && OSTheme === "light") ||
@@ -292,3 +297,12 @@ const updateMobileTheme = (OSTheme: string) => {
}, 500); // 移动端需要加载完才可以获取到颜色
}
};
+
+export const getThemeMode = () => {
+ const OSTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
+ if (window.siyuan.config.appearance.modeOS) {
+ return OSTheme;
+ } else {
+ return window.siyuan.config.appearance.mode === 0 ? "light" : "dark";
+ }
+}