🎨 Improve exporting document HTML (#16219)

* 🎨 The browser-side supports exporting document HTML

fix https://github.com/siyuan-note/siyuan/issues/16213

* 修复导出 HTML 时引入资源没有使用相对路径,修复文档导出 HTML/PDF 时缺失图标

fix https://github.com/siyuan-note/siyuan/issues/16217

fix https://github.com/siyuan-note/siyuan/issues/16216 01

* 修复文档导出 HTML/PDF 时冗余图标

fix https://github.com/siyuan-note/siyuan/issues/16216 02
This commit is contained in:
Jeffrey Chen 2025-10-28 09:28:56 +08:00 committed by GitHub
parent bca1f1eda6
commit 90a447f914
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 241 additions and 40 deletions

View file

@ -766,7 +766,8 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
if 1 == Conf.Appearance.Mode {
theme = Conf.Appearance.ThemeDark
}
srcs = []string{"icons", "themes/" + theme}
// 复制主题文件夹
srcs = []string{"themes/" + theme}
appearancePath := util.AppearancePath
if util.IsSymlinkPath(util.AppearancePath) {
// Support for symlinked theme folder when exporting HTML https://github.com/siyuan-note/siyuan/issues/9173
@ -787,6 +788,35 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
}
}
// 只复制图标文件夹中的 icon.js 文件
iconName := Conf.Appearance.Icon
// 如果使用的不是内建图标ant 或 material需要复制 material 作为后备
if iconName != "ant" && iconName != "material" && iconName != "" {
srcIconFile := filepath.Join(appearancePath, "icons", "material", "icon.js")
toIconDir := filepath.Join(savePath, "appearance", "icons", "material")
if err := os.MkdirAll(toIconDir, 0755); err != nil {
logging.LogErrorf("mkdir [%s] failed: %s", toIconDir, err)
return
}
toIconFile := filepath.Join(toIconDir, "icon.js")
if err := filelock.Copy(srcIconFile, toIconFile); err != nil {
logging.LogWarnf("copy icon file from [%s] to [%s] failed: %s", srcIconFile, toIconFile, err)
}
}
// 复制当前使用的图标文件
if iconName != "" {
srcIconFile := filepath.Join(appearancePath, "icons", iconName, "icon.js")
toIconDir := filepath.Join(savePath, "appearance", "icons", iconName)
if err := os.MkdirAll(toIconDir, 0755); err != nil {
logging.LogErrorf("mkdir [%s] failed: %s", toIconDir, err)
return
}
toIconFile := filepath.Join(toIconDir, "icon.js")
if err := filelock.Copy(srcIconFile, toIconFile); err != nil {
logging.LogWarnf("copy icon file from [%s] to [%s] failed: %s", srcIconFile, toIconFile, err)
}
}
// 复制自定义表情图片
emojis := emojisInTree(tree)
for _, emoji := range emojis {
@ -930,7 +960,8 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do
if 1 == Conf.Appearance.Mode {
theme = Conf.Appearance.ThemeDark
}
srcs = []string{"icons", "themes/" + theme}
// 复制主题文件夹
srcs = []string{"themes/" + theme}
appearancePath := util.AppearancePath
if util.IsSymlinkPath(util.AppearancePath) {
// Support for symlinked theme folder when exporting HTML https://github.com/siyuan-note/siyuan/issues/9173
@ -949,6 +980,35 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do
}
}
// 只复制图标文件夹中的 icon.js 文件
iconName := Conf.Appearance.Icon
// 如果使用的不是内建图标ant 或 material需要复制 material 作为后备
if iconName != "ant" && iconName != "material" && iconName != "" {
srcIconFile := filepath.Join(appearancePath, "icons", "material", "icon.js")
toIconDir := filepath.Join(savePath, "appearance", "icons", "material")
if err := os.MkdirAll(toIconDir, 0755); err != nil {
logging.LogErrorf("mkdir [%s] failed: %s", toIconDir, err)
return
}
toIconFile := filepath.Join(toIconDir, "icon.js")
if err := filelock.Copy(srcIconFile, toIconFile); err != nil {
logging.LogWarnf("copy icon file from [%s] to [%s] failed: %s", srcIconFile, toIconFile, err)
}
}
// 复制当前使用的图标文件
if iconName != "" {
srcIconFile := filepath.Join(appearancePath, "icons", iconName, "icon.js")
toIconDir := filepath.Join(savePath, "appearance", "icons", iconName)
if err := os.MkdirAll(toIconDir, 0755); err != nil {
logging.LogErrorf("mkdir [%s] failed: %s", toIconDir, err)
return
}
toIconFile := filepath.Join(toIconDir, "icon.js")
if err := filelock.Copy(srcIconFile, toIconFile); err != nil {
logging.LogWarnf("copy icon file from [%s] to [%s] failed: %s", srcIconFile, toIconFile, err)
}
}
// 复制自定义表情图片
emojis := emojisInTree(tree)
for _, emoji := range emojis {