mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-03 07:18:49 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
d63c63bbd7
3 changed files with 29 additions and 22 deletions
|
|
@ -42,8 +42,15 @@ func getSnippet(c *gin.Context) {
|
|||
enabled = false
|
||||
}
|
||||
|
||||
confSnippets, err := model.LoadSnippets()
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = "load snippets failed: " + err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
var snippets []*conf.Snippet
|
||||
for _, s := range model.Snippets {
|
||||
for _, s := range confSnippets {
|
||||
if ("all" == typ || s.Type == typ) && (2 == enabledArg || s.Enabled == enabled) {
|
||||
snippets = append(snippets, s)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -296,9 +296,8 @@ func GetHeadingLevelTransaction(id string, level int) (transaction *Transaction,
|
|||
children = append(children, node)
|
||||
children = append(children, treenode.HeadingChildren(node)...)
|
||||
for _, c := range children {
|
||||
if ast.NodeHeading == c.Type {
|
||||
childrenHeadings = append(childrenHeadings, c)
|
||||
}
|
||||
ccH := c.ChildrenByType(ast.NodeHeading)
|
||||
childrenHeadings = append(childrenHeadings, ccH...)
|
||||
}
|
||||
|
||||
transaction = &Transaction{}
|
||||
|
|
|
|||
|
|
@ -285,7 +285,6 @@ func InitConf() {
|
|||
}
|
||||
|
||||
util.SetNetworkProxy(Conf.System.NetworkProxy.String())
|
||||
loadSnippets()
|
||||
}
|
||||
|
||||
var langs = map[string]map[int]string{}
|
||||
|
|
@ -661,26 +660,28 @@ func clearWorkspaceTemp() {
|
|||
logging.LogInfof("cleared workspace temp")
|
||||
}
|
||||
|
||||
var Snippets []*conf.Snippet // js/css 代码片段配置
|
||||
var loadSnippetsLock = sync.Mutex{}
|
||||
|
||||
func loadSnippets() {
|
||||
Snippets = []*conf.Snippet{}
|
||||
func LoadSnippets() (ret []*conf.Snippet, err error) {
|
||||
loadSnippetsLock.Lock()
|
||||
defer loadSnippetsLock.Unlock()
|
||||
|
||||
ret = []*conf.Snippet{}
|
||||
confPath := filepath.Join(util.DataDir, "snippets/conf.json")
|
||||
var data []byte
|
||||
var err error
|
||||
|
||||
if gulu.File.IsExist(confPath) {
|
||||
data, err = filelock.ReadFile(confPath)
|
||||
if nil != err {
|
||||
logging.LogErrorf("load js snippets failed: %s", err)
|
||||
} else {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &Snippets); nil != err {
|
||||
logging.LogErrorf("unmarshal js snippets failed: %s", err)
|
||||
} else {
|
||||
logging.LogInfof("loaded js snippets [%d]", len(Snippets))
|
||||
}
|
||||
}
|
||||
if !gulu.File.IsExist(confPath) {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := filelock.ReadFile(confPath)
|
||||
if nil != err {
|
||||
logging.LogErrorf("load js snippets failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
|
||||
logging.LogErrorf("unmarshal js snippets failed: %s", err)
|
||||
return
|
||||
}
|
||||
logging.LogInfof("loaded js snippets [%d]", len(ret))
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue