Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
6109143c19
2 changed files with 54 additions and 3 deletions
|
@ -26,6 +26,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
|
@ -118,7 +119,6 @@ func getDynamicIcon(c *gin.Context) {
|
|||
color := c.Query("color") // 不要预设默认值,不然type6返回星期就没法自动设置周末颜色了
|
||||
date := c.Query("date")
|
||||
lang := c.DefaultQuery("lang", util.Lang)
|
||||
content := c.Query("content")
|
||||
weekdayType := c.DefaultQuery("weekdayType", "1") // 设置星期几的格式,zh_CH {1:周日,2:周天, 3:星期日,4:星期天,}, en_US {1: Mon, 2: MON,3: Monday, 4. MONDAY,}
|
||||
|
||||
dateInfo := getDateInfo(date, lang, weekdayType)
|
||||
|
@ -147,7 +147,9 @@ func getDynamicIcon(c *gin.Context) {
|
|||
svg = generateTypeSevenSVG(color, lang, dateInfo)
|
||||
case "8":
|
||||
// Type 8: 文字图标
|
||||
svg = generateTypeEightSVG(color, content)
|
||||
content := c.Query("content")
|
||||
id := c.Query("id")
|
||||
svg = generateTypeEightSVG(color, content, id)
|
||||
default:
|
||||
// 默认为Type 1
|
||||
svg = generateTypeOneSVG(color, lang, dateInfo)
|
||||
|
@ -518,7 +520,7 @@ func generateTypeSevenSVG(color string, lang string, dateInfo map[string]interfa
|
|||
}
|
||||
|
||||
// Type 8: 文字图标
|
||||
func generateTypeEightSVG(color, content string) string {
|
||||
func generateTypeEightSVG(color, content, id string) string {
|
||||
colorScheme := getColorScheme(color)
|
||||
|
||||
// 动态变化字体大小
|
||||
|
@ -556,6 +558,10 @@ func generateTypeEightSVG(color, content string) string {
|
|||
}
|
||||
}
|
||||
|
||||
if strings.Contains(content, ".action{") {
|
||||
content = model.RenderDynamicIconContentTemplate(content, id)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(`
|
||||
<svg id="dynamic_icon_type8" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
|
||||
<path d="M39,0h434c20.97,0,38,17.03,38,38v412c0,33.11-26.89,60-60,60H60c-32.56,0-59-26.44-59-59V38C1,17.03,18.03,0,39,0Z" style="fill: %s;"/>
|
||||
|
|
|
@ -193,6 +193,51 @@ func DocSaveAsTemplate(id, name string, overwrite bool) (code int, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func RenderDynamicIconContentTemplate(content, id string) (ret string) {
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
node := treenode.GetNodeInTree(tree, id)
|
||||
if nil == node {
|
||||
return
|
||||
}
|
||||
block := sql.BuildBlockFromNode(node, tree)
|
||||
if nil == block {
|
||||
return
|
||||
}
|
||||
|
||||
dataModel := map[string]string{}
|
||||
title := block.Name
|
||||
if "d" == block.Type {
|
||||
title = block.Content
|
||||
}
|
||||
dataModel["title"] = title
|
||||
dataModel["id"] = block.ID
|
||||
dataModel["name"] = block.Name
|
||||
dataModel["alias"] = block.Alias
|
||||
|
||||
goTpl := template.New("").Delims(".action{", "}")
|
||||
tplFuncMap := treenode.BuiltInTemplateFuncs()
|
||||
sql.SQLTemplateFuncs(&tplFuncMap)
|
||||
goTpl = goTpl.Funcs(tplFuncMap)
|
||||
tpl, err := goTpl.Funcs(tplFuncMap).Parse(content)
|
||||
if err != nil {
|
||||
err = errors.New(fmt.Sprintf(Conf.Language(44), err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
buf.Grow(4096)
|
||||
if err = tpl.Execute(buf, dataModel); err != nil {
|
||||
err = errors.New(fmt.Sprintf(Conf.Language(44), err.Error()))
|
||||
return
|
||||
}
|
||||
ret = buf.String()
|
||||
return
|
||||
}
|
||||
|
||||
func RenderTemplate(p, id string, preview bool) (tree *parse.Tree, dom string, err error) {
|
||||
tree, err = LoadTreeByBlockID(id)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue