Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2022-10-26 23:12:57 +08:00
commit 4a1c26fb85
9 changed files with 275 additions and 46 deletions

View file

@ -115,7 +115,7 @@
"type": "Type",
"searchType": "Type (searches in the enabled types below, the filter option in the global search overrides this setting)",
"searchAttr": "Attribute (search not only in the content, but also in the following enabled attributes)",
"searchBackmention": "Backlink Mentions (backlink mentions search keywords are obtained from)",
"searchBackmention": "Backlink mentions (backlink mentions search keywords are obtained from)",
"searchVirtualRef": "Virtual reference (virtual reference search keywords are obtained from)",
"netImg2LocalAsset": "Convert network images to local images",
"releaseDate": "Release Date",

View file

@ -115,7 +115,7 @@
"type": "Tipo",
"searchType": "Tipos (busque en los tipos habilitados a continuación, la opción de filtro en la búsqueda global anula esta configuración)",
"searchAttr": "Atributo (busca no sólo en el contenido, sino también en los siguientes atributos habilitados)",
"searchBackmention": "Menciones de Backlinks (las menciones de backlinks de las que se obtienen las palabras clave de la búsqueda)",
"searchBackmention": "Menciones de backlinks (las menciones de backlinks de las que se obtienen las palabras clave de la búsqueda)",
"searchVirtualRef": "Referencia virtual (las palabras clave de búsqueda de referencias virtuales se obtienen a partir de ellas)",
"netImg2LocalAsset": "Convertir imágenes de red en imágenes locales",
"releaseDate": "Fecha de lanzamiento",

View file

@ -6,7 +6,7 @@
"id": "20200924101200-gss5vee",
"title": "Navigate in the Content Block",
"type": "doc",
"updated": "20220312233028"
"updated": "20221026222138"
},
"Children": [
{
@ -430,17 +430,70 @@
"ID": "20210106204954-rpwfh3i",
"Type": "NodeParagraph",
"Properties": {
"id": "20210106204954-rpwfh3i"
"id": "20210106204954-rpwfh3i",
"updated": "20221026221426"
},
"Children": [
{
"Type": "NodeText",
"Data": "It is mentioned that the name and aliases of the content block in the current document is used as a keyword to search, and the search result is a content block containing these keywords. You can use the link button to convert the mention into a link: the mention will be replaced with "
"Data": "Mentions are searched using the content block name, alias, reference anchor text and document name in the current document as keywords (the search scope can be set in "
},
{
"Type": "NodeTextMark",
"TextMarkType": "code",
"TextMarkTextContent": "((id \"content block name\"))"
"TextMarkType": "kbd",
"TextMarkTextContent": "Settings"
},
{
"Type": "NodeText",
"Data": " - "
},
{
"Type": "NodeTextMark",
"TextMarkType": "kbd",
"TextMarkTextContent": "Search"
},
{
"Type": "NodeText",
"Data": " - "
},
{
"Type": "NodeTextMark",
"TextMarkType": "kbd",
"TextMarkTextContent": "Backlink mentions"
},
{
"Type": "NodeText",
"Data": "), the search results are blocks of content that contain these keywords."
}
]
},
{
"ID": "20221026222024-1ug5zq4",
"Type": "NodeParagraph",
"Properties": {
"id": "20221026222024-1ug5zq4",
"updated": "20221026222138"
},
"Children": [
{
"Type": "NodeText",
"Data": ""
},
{
"Type": "NodeTextMark",
"TextMarkType": "tag",
"TextMarkTextContent": "Note"
},
{
"Type": "NodeText",
"Data": ": Mention search will only search in normal text, not in line-level elements such as bold and italics, and block-level elements such as code blocks and charts. The rule are the same as the "
},
{
"Type": "NodeTextMark",
"TextMarkType": "block-ref",
"TextMarkBlockRefID": "20211010212319-oy401ib",
"TextMarkBlockRefSubtype": "s",
"TextMarkTextContent": "detection rules of virtual reference"
},
{
"Type": "NodeText",

View file

@ -6,7 +6,7 @@
"id": "20200813131152-0wk5akh",
"title": "在内容块中遨游",
"type": "doc",
"updated": "20220312233009"
"updated": "20221026222004"
},
"Children": [
{
@ -433,21 +433,74 @@
"ID": "20210106201743-z1iz0ce",
"Type": "NodeParagraph",
"Properties": {
"id": "20210106201743-z1iz0ce"
"id": "20210106201743-z1iz0ce",
"updated": "20221026221118"
},
"Children": [
{
"Type": "NodeText",
"Data": "提及使用当前文档中内容块名称和别名作为关键字进行搜索,搜索结果为包含这些关键字的内容块。可以通过链接按钮将提及转换为链接:提及处会使用 "
"Data": "提及使用当前文档中内容块命名、别名、引用锚文本和文档名作为关键字进行搜索(可在 "
},
{
"Type": "NodeTextMark",
"TextMarkType": "code",
"TextMarkTextContent": "((id \"内容块名称\"))"
"TextMarkType": "kbd",
"TextMarkTextContent": "设置"
},
{
"Type": "NodeText",
"Data": " 进行替换。"
"Data": " - "
},
{
"Type": "NodeTextMark",
"TextMarkType": "kbd",
"TextMarkTextContent": "搜索"
},
{
"Type": "NodeText",
"Data": " - "
},
{
"Type": "NodeTextMark",
"TextMarkType": "kbd",
"TextMarkTextContent": "反链提及"
},
{
"Type": "NodeText",
"Data": " 中设置搜索范围),搜索结果为包含这些关键字的内容块。"
}
]
},
{
"ID": "20221026221105-dyj8l8n",
"Type": "NodeParagraph",
"Properties": {
"id": "20221026221105-dyj8l8n",
"updated": "20221026222004"
},
"Children": [
{
"Type": "NodeText",
"Data": ""
},
{
"Type": "NodeTextMark",
"TextMarkType": "tag",
"TextMarkTextContent": "注意"
},
{
"Type": "NodeText",
"Data": "​:提及搜索仅会在普通文本中搜索,不会在粗体、斜体等行级元素和代码块、图表等块级元素中搜索,这一点和"
},
{
"Type": "NodeTextMark",
"TextMarkType": "block-ref",
"TextMarkBlockRefID": "20211010211708-0qn8cpl",
"TextMarkBlockRefSubtype": "s",
"TextMarkTextContent": "虚拟引用探测规则"
},
{
"Type": "NodeText",
"Data": "是相同的。"
}
]
}

View file

@ -5,7 +5,7 @@
"Properties": {
"id": "20211226120349-rbkmozu",
"title": "在内容塊中遨遊",
"updated": "20220312233003"
"updated": "20221026222236"
},
"Children": [
{
@ -380,21 +380,39 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20211226120415-k8yvb62",
"updated": "20211226152312"
"updated": "20221026221359"
},
"Children": [
{
"Type": "NodeText",
"Data": "提及使用當前文檔中內容塊名稱和別名作為關鍵字進行搜索,搜索結果為包含這些關鍵字的內容塊。可以通過連結按鈕將提及轉換為連結:提及處會使用 "
"Data": "提及使用當前文檔中內容塊命名、別名、引用錨文本和文檔名作為關鍵字進行搜索(可在 "
},
{
"Type": "NodeTextMark",
"TextMarkType": "code",
"TextMarkTextContent": "((id \"內容塊名稱\"))"
"TextMarkType": "kbd",
"TextMarkTextContent": "設置"
},
{
"Type": "NodeText",
"Data": " 進行替換。"
"Data": " - "
},
{
"Type": "NodeTextMark",
"TextMarkType": "kbd",
"TextMarkTextContent": "搜索"
},
{
"Type": "NodeText",
"Data": " - "
},
{
"Type": "NodeTextMark",
"TextMarkType": "kbd",
"TextMarkTextContent": "反鏈提及"
},
{
"Type": "NodeText",
"Data": " 中設置搜索範圍),搜索結果為包含這些關鍵字的內容塊。"
}
]
},
@ -403,8 +421,34 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20211228134547-inyam43",
"updated": "20211228134547"
}
"updated": "20221026222236"
},
"Children": [
{
"Type": "NodeText",
"Data": ""
},
{
"Type": "NodeTextMark",
"TextMarkType": "tag",
"TextMarkTextContent": "注意"
},
{
"Type": "NodeText",
"Data": "​:提及搜索僅會在普通文本中搜索,不會在粗體、斜體等行級元素和代碼塊、圖表等塊級元素中搜索,這一點和"
},
{
"Type": "NodeTextMark",
"TextMarkType": "block-ref",
"TextMarkBlockRefID": "20211226122825-w6wxq0c",
"TextMarkBlockRefSubtype": "s",
"TextMarkTextContent": "虛擬引用探測規則"
},
{
"Type": "NodeText",
"Data": "是相同的。"
}
]
}
]
}

View file

@ -283,5 +283,6 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/notification/pushErrMsg", model.CheckAuth, pushErrMsg)
ginServer.Handle("POST", "/api/snippet/getSnippet", model.CheckAuth, getSnippet)
ginServer.Handle("POST", "/api/snippet/setSnippet", model.CheckAuth, setSnippet)
ginServer.Handle("GET", "/snippets/*filepath", serveSnippets)
}

View file

@ -88,3 +88,24 @@ func getSnippet(c *gin.Context) {
"snippets": snippets,
}
}
func setSnippet(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
arg, ok := util.JsonArg(c, ret)
if !ok {
return
}
name := arg["name"].(string)
typ := arg["type"].(string)
content := arg["content"].(string)
enabled := arg["enabled"].(bool)
err := model.SetSnippet(name, typ, content, enabled)
if nil != err {
ret.Code = -1
ret.Msg = "set snippet failed: " + err.Error()
return
}
}

View file

@ -696,28 +696,3 @@ func clearWorkspaceTemp() {
logging.LogInfof("cleared workspace temp")
}
var loadSnippetsLock = sync.Mutex{}
func LoadSnippets() (ret []*conf.Snippet, err error) {
loadSnippetsLock.Lock()
defer loadSnippetsLock.Unlock()
ret = []*conf.Snippet{}
confPath := filepath.Join(util.DataDir, "snippets/conf.json")
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
}
return
}

82
kernel/model/snippet.go Normal file
View file

@ -0,0 +1,82 @@
// SiYuan - Build Your Eternal Digital Garden
// Copyright (c) 2020-present, b3log.org
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// 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/>.
package model
import (
"path/filepath"
"sync"
"github.com/88250/gulu"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/util"
)
var snippetsLock = sync.Mutex{}
func SetSnippet(name, typ, content string, enabled bool) (err error) {
snippetsLock.Lock()
defer snippetsLock.Unlock()
snippets, err := loadSnippets()
if nil != err {
return
}
snippet := &conf.Snippet{Name: name, Type: typ, Content: content, Enabled: enabled}
snippets = append(snippets, snippet)
err = writeSnippetsConf(snippets)
return
}
func LoadSnippets() (ret []*conf.Snippet, err error) {
snippetsLock.Lock()
defer snippetsLock.Unlock()
return loadSnippets()
}
func loadSnippets() (ret []*conf.Snippet, err error) {
ret = []*conf.Snippet{}
confPath := filepath.Join(util.DataDir, "snippets/conf.json")
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
}
return
}
func writeSnippetsConf(snippets []*conf.Snippet) (err error) {
data, err := gulu.JSON.MarshalIndentJSON(snippets, "", " ")
if nil != err {
logging.LogErrorf("marshal snippets failed: %s", err)
return
}
confPath := filepath.Join(util.DataDir, "snippets/conf.json")
err = filelock.WriteFile(confPath, data)
return
}