Skip to content

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

:art: Improve exporting document HTML (#16225)

Jeffrey Chened4db690a501
diff --git a/app/src/menus/commonMenuItem.ts b/app/src/menus/commonMenuItem.ts
index 3263c5498e..04671a8260 100644
--- a/app/src/menus/commonMenuItem.ts
+++ b/app/src/menus/commonMenuItem.ts
@@ -767,7 +767,8 @@ export const exportMd = (id: string) => {
keepFold: localData.keepFold,
merge: localData.mergeSubdocs,
}, async response => {
- const html = await onExport(response, undefined, {type: "pdf", id});
+ const servePath = window.location.protocol + "//" + window.location.host + "/";
+ const html = await onExport(response, undefined, servePath, {type: "pdf", id});
if (isInAndroid()) {
window.JSAndroid.print(html);
} else if (isInHarmony()) {
diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts
index 26edcda100..306a71cdff 100644
--- a/app/src/protyle/export/index.ts
+++ b/app/src/protyle/export/index.ts
@@ -43,7 +43,7 @@ export const saveExport = (option: IExportOptions) => {
merge: true,
savePath: ""
}, async exportResponse => {
- const html = await onExport(exportResponse, undefined, option);
+ const html = await onExport(exportResponse, undefined, "", option);
fetchPost("/api/export/exportBrowserHTML", {
folder: exportResponse.data.folder,
html: html,
@@ -684,7 +684,7 @@ const getExportPath = (option: IExportOptions, removeAssets?: boolean, mergeSubd
}
afterExport(exportResponse.data.path, msgId);
} else {
- onExport(exportResponse, savePath, option, msgId);
+ onExport(exportResponse, savePath, "", option, msgId);
}
});
}
@@ -692,7 +692,7 @@ const getExportPath = (option: IExportOptions, removeAssets?: boolean, mergeSubd
};
/// #endif
-export const onExport = async (data: IWebSocketData, filePath: string, exportOption: IExportOptions, msgId?: string) => {
+export const onExport = async (data: IWebSocketData, filePath: string, servePath: string, exportOption: IExportOptions, msgId?: string) => {
let themeName = window.siyuan.config.appearance.themeLight;
let mode = 0;
if (["html", "htmlmd"].includes(exportOption.type) && window.siyuan.config.appearance.mode === 1) {
@@ -700,8 +700,6 @@ export const onExport = async (data: IWebSocketData, filePath: string, exportOpt
mode = 1;
}
const isDefault = (window.siyuan.config.appearance.mode === 1 && window.siyuan.config.appearance.themeDark === "midnight") || (window.siyuan.config.appearance.mode === 0 && window.siyuan.config.appearance.themeLight === "daylight");
- const isLocalExport = typeof filePath !== "undefined";
- const servePath = isLocalExport ? "" : window.location.protocol + "//" + window.location.host + "/";
let themeStyle = "";
if (!isDefault) {
themeStyle = `<link rel="stylesheet" type="text/css" id="themeStyle" href="${servePath}appearance/themes/${themeName}/theme.css?${Constants.SIYUAN_VERSION}"/>`;