Improve export preview mode CSS variable value filling (#15110)

* 改进 CSS 变量替换为实际值

* Chrome、Edge、SiYuan 桌面端不需要替换 CSS 变量

* 外观模式或主题改变之后,重新加载所有将 CSS 变量替换为实际值的导出预览

* 代码块之间没有间距

* 去掉一个空格

* 使用 ua.Mobile() 判断移动设备

* 重构
This commit is contained in:
Jeffrey Chen 2025-07-29 21:33:40 +08:00 committed by GitHub
parent 449b537104
commit 2994969286
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 235 additions and 43 deletions

View file

@ -29,6 +29,7 @@ import (
"github.com/88250/gulu"
"github.com/88250/lute/parse"
"github.com/gin-gonic/gin"
"github.com/mssola/useragent"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/util"
@ -627,9 +628,22 @@ func exportPreview(c *gin.Context) {
}
id := arg["id"].(string)
stdHTML := model.Preview(id)
userAgentStr := c.GetHeader("User-Agent")
fillCSSVar := true
if userAgentStr != "" {
ua := useragent.New(userAgentStr)
name, _ := ua.Browser()
// Chrome、Edge、SiYuan 桌面端不需要替换 CSS 变量
if !ua.Mobile() && (name == "Chrome" || name == "Edge" || strings.Contains(userAgentStr, "Electron") || strings.Contains(userAgentStr, "SiYuan/")) {
fillCSSVar = false
}
}
stdHTML := model.Preview(id, fillCSSVar)
ret.Data = map[string]interface{}{
"html": stdHTML,
"html": stdHTML,
"fillCSSVar": fillCSSVar,
}
}