mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-22 23:14:07 +01:00
🎨 Support focus block export template https://github.com/siyuan-note/siyuan/issues/8117
This commit is contained in:
parent
9cb6e9ec25
commit
1c47a63cca
4 changed files with 63 additions and 27 deletions
|
|
@ -54,8 +54,9 @@ func docSaveAsTemplate(c *gin.Context) {
|
|||
}
|
||||
|
||||
id := arg["id"].(string)
|
||||
name := arg["name"].(string)
|
||||
overwrite := arg["overwrite"].(bool)
|
||||
code, err := model.DocSaveAsTemplate(id, overwrite)
|
||||
code, err := model.DocSaveAsTemplate(id, name, overwrite)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = util.EscapeHTML(err.Error())
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5 h1:8HdZozCsXS
|
|||
github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/88250/gulu v1.2.3-0.20230321113152-38c4a3d73c37 h1:7ZMvlXDbH2sqaxowoAFcLjcdRN7ncVE0U1S2ukpUgac=
|
||||
github.com/88250/gulu v1.2.3-0.20230321113152-38c4a3d73c37/go.mod h1:pTWnjt+6qUqNnP9xltswsJxgCBVu3C7eW09u48LWX0k=
|
||||
github.com/88250/lute v1.7.6-0.20230426013259-afae190c74ff h1:gWI6ch+YgmecbRpkLzq8mf9HiYWybEYCHcy+Szwelyg=
|
||||
github.com/88250/lute v1.7.6-0.20230426013259-afae190c74ff/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
|
||||
github.com/88250/lute v1.7.6-0.20230427065909-d447ad8fc493 h1:F6C9dVvQVwxCOAd88Ea4WchCzR6Ekr/Q4IiqLYWfDyw=
|
||||
github.com/88250/lute v1.7.6-0.20230427065909-d447ad8fc493/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
|
||||
|
|
|
|||
|
|
@ -132,21 +132,20 @@ func SearchTemplate(keyword string) (ret []*Block) {
|
|||
return
|
||||
}
|
||||
|
||||
func DocSaveAsTemplate(id string, overwrite bool) (code int, err error) {
|
||||
tree, err := loadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
func DocSaveAsTemplate(id, name string, overwrite bool) (code int, err error) {
|
||||
bt := treenode.GetBlockTree(id)
|
||||
if nil == bt {
|
||||
return
|
||||
}
|
||||
|
||||
tree := prepareExportTree(bt)
|
||||
addBlockIALNodes(tree, true)
|
||||
|
||||
luteEngine := NewLute()
|
||||
formatRenderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions)
|
||||
md := formatRenderer.Render()
|
||||
title := tree.Root.IALAttr("title")
|
||||
title = util.FilterFileName(title)
|
||||
title += ".md"
|
||||
savePath := filepath.Join(util.DataDir, "templates", title)
|
||||
name = util.FilterFileName(name) + ".md"
|
||||
savePath := filepath.Join(util.DataDir, "templates", name)
|
||||
if gulu.File.IsExist(savePath) {
|
||||
if !overwrite {
|
||||
code = 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue