mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 06:31:06 +08:00
🎨 Add internal kernel API /api/setting/addVirtualBlockRefInclude
and addVirtualBlockRefExclude
https://github.com/siyuan-note/siyuan/issues/9909
This commit is contained in:
parent
65fbfc5a1f
commit
32ce33d0fb
@ -308,6 +308,8 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||
ginServer.Handle("POST", "/api/setting/setAI", model.CheckAuth, model.CheckReadonly, setAI)
|
||||
ginServer.Handle("POST", "/api/setting/setBazaar", model.CheckAuth, model.CheckReadonly, setBazaar)
|
||||
ginServer.Handle("POST", "/api/setting/refreshVirtualBlockRef", model.CheckAuth, model.CheckReadonly, refreshVirtualBlockRef)
|
||||
ginServer.Handle("POST", "/api/setting/addVirtualBlockRefInclude", model.CheckAuth, model.CheckReadonly, addVirtualBlockRefInclude)
|
||||
ginServer.Handle("POST", "/api/setting/addVirtualBlockRefExclude", model.CheckAuth, model.CheckReadonly, addVirtualBlockRefExclude)
|
||||
|
||||
ginServer.Handle("POST", "/api/graph/resetGraph", model.CheckAuth, model.CheckReadonly, resetGraph)
|
||||
ginServer.Handle("POST", "/api/graph/resetLocalGraph", model.CheckAuth, model.CheckReadonly, resetLocalGraph)
|
||||
|
@ -29,6 +29,46 @@ import (
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func addVirtualBlockRefExclude(c *gin.Context) {
|
||||
// Add internal kernel API `/api/setting/addVirtualBlockRefExclude` https://github.com/siyuan-note/siyuan/issues/9909
|
||||
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
keywordsArg := arg["keywords"]
|
||||
var keywords []string
|
||||
for _, k := range keywordsArg.([]interface{}) {
|
||||
keywords = append(keywords, k.(string))
|
||||
}
|
||||
|
||||
model.AddVirtualBlockRefExclude(keywords)
|
||||
}
|
||||
|
||||
func addVirtualBlockRefInclude(c *gin.Context) {
|
||||
// Add internal kernel API `/api/setting/addVirtualBlockRefInclude` https://github.com/siyuan-note/siyuan/issues/9909
|
||||
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
keywordsArg := arg["keywords"]
|
||||
var keywords []string
|
||||
for _, k := range keywordsArg.([]interface{}) {
|
||||
keywords = append(keywords, k.(string))
|
||||
}
|
||||
|
||||
model.AddVirtualBlockRefInclude(keywords)
|
||||
}
|
||||
|
||||
func refreshVirtualBlockRef(c *gin.Context) {
|
||||
// Add internal kernel API `/api/setting/refreshVirtualBlockRef` https://github.com/siyuan-note/siyuan/issues/9829
|
||||
|
||||
|
@ -113,6 +113,42 @@ func ResetVirtualBlockRefCache() {
|
||||
CacheVirtualBlockRefJob()
|
||||
}
|
||||
|
||||
func AddVirtualBlockRefInclude(keyword []string) {
|
||||
if 1 > len(keyword) {
|
||||
return
|
||||
}
|
||||
|
||||
Conf.m.Lock()
|
||||
defer Conf.m.Unlock()
|
||||
|
||||
include := strings.ReplaceAll(Conf.Editor.VirtualBlockRefInclude, "\\,", "__comma@sep__")
|
||||
includes := strings.Split(include, ",")
|
||||
includes = append(includes, keyword...)
|
||||
includes = gulu.Str.RemoveDuplicatedElem(includes)
|
||||
Conf.Editor.VirtualBlockRefInclude = strings.Join(includes, ",")
|
||||
Conf.Save()
|
||||
|
||||
ResetVirtualBlockRefCache()
|
||||
}
|
||||
|
||||
func AddVirtualBlockRefExclude(keyword []string) {
|
||||
if 1 > len(keyword) {
|
||||
return
|
||||
}
|
||||
|
||||
Conf.m.Lock()
|
||||
defer Conf.m.Unlock()
|
||||
|
||||
exclude := strings.ReplaceAll(Conf.Editor.VirtualBlockRefExclude, "\\,", "__comma@sep__")
|
||||
excludes := strings.Split(exclude, ",")
|
||||
excludes = append(excludes, keyword...)
|
||||
excludes = gulu.Str.RemoveDuplicatedElem(excludes)
|
||||
Conf.Editor.VirtualBlockRefExclude = strings.Join(excludes, ",")
|
||||
Conf.Save()
|
||||
|
||||
ResetVirtualBlockRefCache()
|
||||
}
|
||||
|
||||
func processVirtualRef(n *ast.Node, unlinks *[]*ast.Node, virtualBlockRefKeywords []string, refCount map[string]int, luteEngine *lute.Lute) bool {
|
||||
if !Conf.Editor.VirtualBlockRef {
|
||||
return false
|
||||
|
Loading…
Reference in New Issue
Block a user