🎨 Improve exporting document HTML (#16225)

fix https://github.com/siyuan-note/siyuan/pull/16219
This commit is contained in:
Jeffrey Chen 2025-10-28 16:21:27 +08:00 committed by GitHub
parent a6b2cc5b2b
commit ed4db690a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 6 deletions

View file

@ -767,7 +767,8 @@ export const exportMd = (id: string) => {
keepFold: localData.keepFold, keepFold: localData.keepFold,
merge: localData.mergeSubdocs, merge: localData.mergeSubdocs,
}, async response => { }, 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()) { if (isInAndroid()) {
window.JSAndroid.print(html); window.JSAndroid.print(html);
} else if (isInHarmony()) { } else if (isInHarmony()) {

View file

@ -43,7 +43,7 @@ export const saveExport = (option: IExportOptions) => {
merge: true, merge: true,
savePath: "" savePath: ""
}, async exportResponse => { }, async exportResponse => {
const html = await onExport(exportResponse, undefined, option); const html = await onExport(exportResponse, undefined, "", option);
fetchPost("/api/export/exportBrowserHTML", { fetchPost("/api/export/exportBrowserHTML", {
folder: exportResponse.data.folder, folder: exportResponse.data.folder,
html: html, html: html,
@ -684,7 +684,7 @@ const getExportPath = (option: IExportOptions, removeAssets?: boolean, mergeSubd
} }
afterExport(exportResponse.data.path, msgId); afterExport(exportResponse.data.path, msgId);
} else { } else {
onExport(exportResponse, savePath, option, msgId); onExport(exportResponse, savePath, "", option, msgId);
} }
}); });
} }
@ -692,7 +692,7 @@ const getExportPath = (option: IExportOptions, removeAssets?: boolean, mergeSubd
}; };
/// #endif /// #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 themeName = window.siyuan.config.appearance.themeLight;
let mode = 0; let mode = 0;
if (["html", "htmlmd"].includes(exportOption.type) && window.siyuan.config.appearance.mode === 1) { 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; 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 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 = ""; let themeStyle = "";
if (!isDefault) { if (!isDefault) {
themeStyle = `<link rel="stylesheet" type="text/css" id="themeStyle" href="${servePath}appearance/themes/${themeName}/theme.css?${Constants.SIYUAN_VERSION}"/>`; themeStyle = `<link rel="stylesheet" type="text/css" id="themeStyle" href="${servePath}appearance/themes/${themeName}/theme.css?${Constants.SIYUAN_VERSION}"/>`;