mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 23:50:13 +01:00
🎨 Add a template function getHPathByID https://github.com/siyuan-note/siyuan/issues/11734
This commit is contained in:
parent
3cd7d9fd3e
commit
0ff99f758a
3 changed files with 19 additions and 8 deletions
|
|
@ -42,7 +42,7 @@ import (
|
||||||
|
|
||||||
func RenderGoTemplate(templateContent string) (ret string, err error) {
|
func RenderGoTemplate(templateContent string) (ret string, err error) {
|
||||||
tmpl := template.New("")
|
tmpl := template.New("")
|
||||||
tplFuncMap := util.BuiltInTemplateFuncs()
|
tplFuncMap := treenode.BuiltInTemplateFuncs()
|
||||||
sql.SQLTemplateFuncs(&tplFuncMap)
|
sql.SQLTemplateFuncs(&tplFuncMap)
|
||||||
tmpl = tmpl.Funcs(tplFuncMap)
|
tmpl = tmpl.Funcs(tplFuncMap)
|
||||||
tpl, err := tmpl.Parse(templateContent)
|
tpl, err := tmpl.Parse(templateContent)
|
||||||
|
|
@ -224,7 +224,7 @@ func RenderTemplate(p, id string, preview bool) (tree *parse.Tree, dom string, e
|
||||||
}
|
}
|
||||||
|
|
||||||
goTpl := template.New("").Delims(".action{", "}")
|
goTpl := template.New("").Delims(".action{", "}")
|
||||||
tplFuncMap := util.BuiltInTemplateFuncs()
|
tplFuncMap := treenode.BuiltInTemplateFuncs()
|
||||||
sql.SQLTemplateFuncs(&tplFuncMap)
|
sql.SQLTemplateFuncs(&tplFuncMap)
|
||||||
goTpl = goTpl.Funcs(tplFuncMap)
|
goTpl = goTpl.Funcs(tplFuncMap)
|
||||||
tpl, err := goTpl.Funcs(tplFuncMap).Parse(gulu.Str.FromBytes(md))
|
tpl, err := goTpl.Funcs(tplFuncMap).Parse(gulu.Str.FromBytes(md))
|
||||||
|
|
|
||||||
|
|
@ -404,7 +404,7 @@ func RenderTemplateCol(ial map[string]string, rowValues []*av.KeyValues, tplCont
|
||||||
}
|
}
|
||||||
|
|
||||||
goTpl := template.New("").Delims(".action{", "}")
|
goTpl := template.New("").Delims(".action{", "}")
|
||||||
tplFuncMap := util.BuiltInTemplateFuncs()
|
tplFuncMap := treenode.BuiltInTemplateFuncs()
|
||||||
SQLTemplateFuncs(&tplFuncMap)
|
SQLTemplateFuncs(&tplFuncMap)
|
||||||
goTpl = goTpl.Funcs(tplFuncMap)
|
goTpl = goTpl.Funcs(tplFuncMap)
|
||||||
tpl, err := goTpl.Parse(tplContent)
|
tpl, err := goTpl.Parse(tplContent)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package util
|
package treenode
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
|
|
@ -25,21 +25,23 @@ import (
|
||||||
"github.com/Masterminds/sprig/v3"
|
"github.com/Masterminds/sprig/v3"
|
||||||
"github.com/araddon/dateparse"
|
"github.com/araddon/dateparse"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BuiltInTemplateFuncs() (ret template.FuncMap) {
|
func BuiltInTemplateFuncs() (ret template.FuncMap) {
|
||||||
ret = sprig.TxtFuncMap()
|
ret = sprig.TxtFuncMap()
|
||||||
ret["Weekday"] = Weekday
|
ret["Weekday"] = util.Weekday
|
||||||
ret["WeekdayCN"] = WeekdayCN
|
ret["WeekdayCN"] = util.WeekdayCN
|
||||||
ret["WeekdayCN2"] = WeekdayCN2
|
ret["WeekdayCN2"] = util.WeekdayCN2
|
||||||
ret["ISOWeek"] = ISOWeek
|
ret["ISOWeek"] = util.ISOWeek
|
||||||
ret["pow"] = pow
|
ret["pow"] = pow
|
||||||
ret["powf"] = powf
|
ret["powf"] = powf
|
||||||
ret["log"] = log
|
ret["log"] = log
|
||||||
ret["logf"] = logf
|
ret["logf"] = logf
|
||||||
ret["parseTime"] = parseTime
|
ret["parseTime"] = parseTime
|
||||||
ret["FormatFloat"] = FormatFloat
|
ret["FormatFloat"] = FormatFloat
|
||||||
|
ret["getHPathByID"] = getHPathByID
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,3 +65,12 @@ func parseTime(dateStr string) time.Time {
|
||||||
func FormatFloat(format string, n float64) string {
|
func FormatFloat(format string, n float64) string {
|
||||||
return humanize.FormatFloat(format, n)
|
return humanize.FormatFloat(format, n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getHPathByID(id string) (ret string) {
|
||||||
|
bt := GetBlockTree(id)
|
||||||
|
if nil == bt {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ret = bt.HPath
|
||||||
|
return
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue