An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Support excluding backlink mention keywords https://github.com/siyuan-note/siyuan/issues/18852
Daniel8360e9eb8fcf
diff --git a/app/appearance/langs/ar.json b/app/appearance/langs/ar.jsonindex a292daa415..2bf1ef583a 100644--- a/app/appearance/langs/ar.json+++ b/app/appearance/langs/ar.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "قائمة استبعاد الكلمات المفتاحية لإشارات الروابط الخلفية","entryToolbar": "شريط الأدوات","appMenuAbout": "حول SiYuan","appMenuServices": "الخدمات",diff --git a/app/appearance/langs/de.json b/app/appearance/langs/de.jsonindex 7731929450..26473f4ce9 100644--- a/app/appearance/langs/de.json+++ b/app/appearance/langs/de.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "Ausschlussliste für Schlüsselwörter in Backlink-Erwähnungen","entryToolbar": "Symbolleiste","appMenuAbout": "Über SiYuan","appMenuServices": "Dienste",diff --git a/app/appearance/langs/en.json b/app/appearance/langs/en.jsonindex cbe565cb4c..014b09ed55 100644--- a/app/appearance/langs/en.json+++ b/app/appearance/langs/en.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "Backlink mention keyword exclusion list","entryToolbar": "Toolbar","appMenuAbout": "About SiYuan","appMenuServices": "Services",diff --git a/app/appearance/langs/es.json b/app/appearance/langs/es.jsonindex 18b7479cdb..f89e6b22af 100644--- a/app/appearance/langs/es.json+++ b/app/appearance/langs/es.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "Lista de exclusión de palabras clave de menciones de enlaces inversos","entryToolbar": "Barra de herramientas","appMenuAbout": "Acerca de SiYuan","appMenuServices": "Servicios",diff --git a/app/appearance/langs/fr.json b/app/appearance/langs/fr.jsonindex bc41bdc3c1..f2e54d3c26 100644--- a/app/appearance/langs/fr.json+++ b/app/appearance/langs/fr.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "Liste d’exclusion des mots-clés des mentions de liens retour","entryToolbar": "Barre d’outils","appMenuAbout": "À propos de SiYuan","appMenuServices": "Services",diff --git a/app/appearance/langs/he.json b/app/appearance/langs/he.jsonindex 88c30d0a25..7ef2cf41ad 100644--- a/app/appearance/langs/he.json+++ b/app/appearance/langs/he.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "רשימת אי-הכללה של מילות מפתח לאזכורי קישורים חוזרים","entryToolbar": "סרגל כלים","appMenuAbout": "אודות SiYuan","appMenuServices": "שירותים",diff --git a/app/appearance/langs/hi.json b/app/appearance/langs/hi.jsonindex 6c02897f07..f89366f962 100644--- a/app/appearance/langs/hi.json+++ b/app/appearance/langs/hi.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "बैकलिंक उल्लेख कीवर्ड बहिष्करण सूची","entryToolbar": "टूलबार","appMenuAbout": "SiYuan के बारे में","appMenuServices": "सेवाएँ",diff --git a/app/appearance/langs/id.json b/app/appearance/langs/id.jsonindex 5c42746394..72ee3ef7cc 100644--- a/app/appearance/langs/id.json+++ b/app/appearance/langs/id.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "Daftar pengecualian kata kunci penyebutan backlink","entryToolbar": "Bilah alat","appMenuAbout": "Tentang SiYuan","appMenuServices": "Layanan",diff --git a/app/appearance/langs/it.json b/app/appearance/langs/it.jsonindex cb9b9de614..87109b3a83 100644--- a/app/appearance/langs/it.json+++ b/app/appearance/langs/it.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "Elenco di esclusione delle parole chiave delle menzioni dei backlink","entryToolbar": "Barra degli strumenti","appMenuAbout": "Informazioni su SiYuan","appMenuServices": "Servizi",diff --git a/app/appearance/langs/ja.json b/app/appearance/langs/ja.jsonindex 0806298cd7..54e46bc545 100644--- a/app/appearance/langs/ja.json+++ b/app/appearance/langs/ja.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "バックリンク言及キーワード除外リスト","entryToolbar": "ツールバー","appMenuAbout": "SiYuan について","appMenuServices": "サービス",diff --git a/app/appearance/langs/ko.json b/app/appearance/langs/ko.jsonindex 0206d82513..39c1a09d58 100644--- a/app/appearance/langs/ko.json+++ b/app/appearance/langs/ko.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "백링크 언급 키워드 제외 목록","entryToolbar": "도구 모음","appMenuAbout": "SiYuan 정보","appMenuServices": "서비스",diff --git a/app/appearance/langs/nl.json b/app/appearance/langs/nl.jsonindex da531001dc..7a282a48ea 100644--- a/app/appearance/langs/nl.json+++ b/app/appearance/langs/nl.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "Uitsluitingslijst voor trefwoorden in backlinkvermeldingen","entryToolbar": "Werkbalk","appMenuAbout": "Over SiYuan","appMenuServices": "Voorzieningen",diff --git a/app/appearance/langs/pl.json b/app/appearance/langs/pl.jsonindex 9e1370afb7..da7a9e5876 100644--- a/app/appearance/langs/pl.json+++ b/app/appearance/langs/pl.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "Lista wykluczeń słów kluczowych wzmianek o linkach zwrotnych","entryToolbar": "Pasek narzędzi","appMenuAbout": "O programie SiYuan","appMenuServices": "Usługi",diff --git a/app/appearance/langs/pt-BR.json b/app/appearance/langs/pt-BR.jsonindex b8109b872c..5ed9a8f794 100644--- a/app/appearance/langs/pt-BR.json+++ b/app/appearance/langs/pt-BR.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "Lista de exclusão de palavras-chave de menções de backlinks","entryToolbar": "Barra de ferramentas","appMenuAbout": "Sobre o SiYuan","appMenuServices": "Serviços",diff --git a/app/appearance/langs/ru.json b/app/appearance/langs/ru.jsonindex e06a7292e9..7c99ca6e25 100644--- a/app/appearance/langs/ru.json+++ b/app/appearance/langs/ru.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "Список исключений ключевых слов для упоминаний обратных ссылок","entryToolbar": "Панель инструментов","appMenuAbout": "О программе SiYuan","appMenuServices": "Службы",diff --git a/app/appearance/langs/sk.json b/app/appearance/langs/sk.jsonindex 1f0ad02c96..c53d8d25e4 100644--- a/app/appearance/langs/sk.json+++ b/app/appearance/langs/sk.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "Zoznam vylúčených kľúčových slov zmienok o spätných odkazoch","entryToolbar": "Panel s nástrojmi","appMenuAbout": "O aplikácii SiYuan","appMenuServices": "Služby",diff --git a/app/appearance/langs/th.json b/app/appearance/langs/th.jsonindex 41d3249029..0b4e47419a 100644--- a/app/appearance/langs/th.json+++ b/app/appearance/langs/th.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "รายการยกเว้นคำสำคัญสำหรับการกล่าวถึงลิงก์ย้อนกลับ","entryToolbar": "แถบเครื่องมือ","appMenuAbout": "เกี่ยวกับ SiYuan","appMenuServices": "บริการ",diff --git a/app/appearance/langs/tr.json b/app/appearance/langs/tr.jsonindex be5a7affdd..07da2bb8d7 100644--- a/app/appearance/langs/tr.json+++ b/app/appearance/langs/tr.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "Geri bağlantı bahsi anahtar kelime hariç tutma listesi","entryToolbar": "Araç çubuğu","appMenuAbout": "SiYuan Hakkında","appMenuServices": "Hizmetler",diff --git a/app/appearance/langs/uk.json b/app/appearance/langs/uk.jsonindex 9ff4ea8f82..62d0ed5c9b 100644--- a/app/appearance/langs/uk.json+++ b/app/appearance/langs/uk.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "Список виключень ключових слів для згадок зворотних посилань","entryToolbar": "Панель інструментів","appMenuAbout": "Про SiYuan","appMenuServices": "Служби",diff --git a/app/appearance/langs/zh-CN.json b/app/appearance/langs/zh-CN.jsonindex c4298488af..ebdb3082b9 100644--- a/app/appearance/langs/zh-CN.json+++ b/app/appearance/langs/zh-CN.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "反链提及关键字排除列表","entryToolbar": "工具栏","appMenuAbout": "关于思源笔记","appMenuServices": "服务",diff --git a/app/appearance/langs/zh-TW.json b/app/appearance/langs/zh-TW.jsonindex 9574d8cffa..9f019c7a44 100644--- a/app/appearance/langs/zh-TW.json+++ b/app/appearance/langs/zh-TW.json@@ -1,4 +1,5 @@{+ "backlinkMentionExclude": "反連提及關鍵字排除列表","entryToolbar": "工具列","appMenuAbout": "關於思源筆記","appMenuServices": "服務",diff --git a/app/src/config/tabs/editorTab.ts b/app/src/config/tabs/editorTab.tsindex 17e161a8b6..642fe6cc2a 100644--- a/app/src/config/tabs/editorTab.ts+++ b/app/src/config/tabs/editorTab.ts@@ -233,6 +233,11 @@ const registerEditorBidirectionalGroup = (tab: SettingTabBuilder) => {desc: window.siyuan.languages.md41,mode: "textarea",});+ group.textBlock("editor.backlinkMentionExclude", {+ title: window.siyuan.languages.backlinkMentionExclude,+ desc: window.siyuan.languages.md41,+ mode: "textarea",+ });group.switch("editor.backlinkContainChildren", {title: window.siyuan.languages.backlinkContainChildren,desc: window.siyuan.languages.backlinkContainChildrenTip,diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.tsindex eea57a0da9..9cddd2d975 100644--- a/app/src/types/config.d.ts+++ b/app/src/types/config.d.ts@@ -536,6 +536,10 @@ declare namespace Config {* The default number of backlinks to mention*/backmentionExpandCount: number;+ /**+ * Backlink mention keyword exclusion list (separated by commas `,`)+ */+ backlinkMentionExclude: string;/*** Whether the backlink contains children*/diff --git a/kernel/conf/editor.go b/kernel/conf/editor.goindex 8d406390f9..fd2e83118c 100644--- a/kernel/conf/editor.go+++ b/kernel/conf/editor.go@@ -62,6 +62,7 @@ type Editor struct {OnlySearchForDoc bool `json:"onlySearchForDoc"` // 是否启用 [[ 仅搜索文档块BacklinkExpandCount int `json:"backlinkExpandCount"` // 反向链接默认展开数量BackmentionExpandCount int `json:"backmentionExpandCount"` // 反链提及默认展开数量+ BacklinkMentionExclude string `json:"backlinkMentionExclude"` // 反链提及关键字排除列表BacklinkContainChildren bool `json:"backlinkContainChildren"` // 反向链接是否包含子块进行计算BacklinkShowBottom bool `json:"backlinkShowBottom"` // 是否在文档底部显示反向链接BacklinkSort *int `json:"backlinkSort"` // 反向链接排序方式diff --git a/kernel/model/backlink.go b/kernel/model/backlink.goindex acca9b1a21..f1d5d3a53b 100644--- a/kernel/model/backlink.go+++ b/kernel/model/backlink.go@@ -989,6 +989,7 @@ func buildTreeBackmentionInBox(defSQLBlock *sql.Block, refBlocks []*Block, keywofor _, v := range set.Values() {mentionKeywords = append(mentionKeywords, v.(string))}+ mentionKeywords = excludeKeywords(mentionKeywords, Conf.Editor.BacklinkMentionExclude)mentionKeywords = prepareMarkKeywords(mentionKeywords)mentionKeywords, ret = searchBackmentionInBox(mentionKeywords, keyword, excludeBacklinkIDs, rootID, beforeLen, boxID)returndiff --git a/kernel/model/keyword_filter_test.go b/kernel/model/keyword_filter_test.gonew file mode 100644index 0000000000..7f1afd62bd--- /dev/null+++ b/kernel/model/keyword_filter_test.go@@ -0,0 +1,41 @@+// SiYuan - From thought to insight, with agents+// 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 (+ "reflect"+ "testing"+)++func TestExcludeKeywords(t *testing.T) {+ keywords := []string{"work", "test", "entropy", "foo123", "/"}+ excludes := "work, /^test$/\n/[0-9]+/,/"+ want := []string{"entropy"}++ if got := excludeKeywords(keywords, excludes); !reflect.DeepEqual(got, want) {+ t.Fatalf("excludeKeywords() = %q, want %q", got, want)+ }+}++func TestExcludeKeywordsIgnoresInvalidRegexp(t *testing.T) {+ keywords := []string{"work", "test"}+ want := []string{"work", "test"}++ if got := excludeKeywords(keywords, "/[/"); !reflect.DeepEqual(got, want) {+ t.Fatalf("excludeKeywords() = %q, want %q", got, want)+ }+}diff --git a/kernel/model/virutalref.go b/kernel/model/virutalref.goindex 2632870f43..fa17545ae9 100644--- a/kernel/model/virutalref.go+++ b/kernel/model/virutalref.go@@ -301,24 +301,47 @@ func getVirtualRefKeywords(root *ast.Node, boxIDs ...string) (ret []string) {ret = gulu.Str.RemoveDuplicatedElem(ret)}- excludes := parseKeywords(Conf.Editor.VirtualBlockRefExclude)+ ret = excludeKeywords(ret, Conf.Editor.VirtualBlockRefExclude)++ // 虚拟引用排除当前文档名 https://github.com/siyuan-note/siyuan/issues/4537+ // Virtual references exclude the name and aliases from the current document https://github.com/siyuan-note/siyuan/issues/9204+ title := root.IALAttr("title")+ ret = gulu.Str.ExcludeElem(ret, []string{title})+ if name := root.IALAttr("name"); "" != name {+ ret = gulu.Str.ExcludeElem(ret, []string{name})+ }+ if alias := root.IALAttr("alias"); "" != alias {+ for a := range strings.SplitSeq(alias, ",") {+ ret = gulu.Str.ExcludeElem(ret, []string{a})+ }+ }++ ret = prepareMarkKeywords(ret)+ return+}++func excludeKeywords(keywords []string, excludesStr string) (ret []string) {+ excludes := parseKeywords(excludesStr)if 0 < len(excludes) {- var tmp, regexps []string+ var tmp []string+ var regexps []*regexp.Regexpfor _, e := range excludes {- if strings.HasPrefix(e, "/") && strings.HasSuffix(e, "/") {- regexps = append(regexps, e[1:len(e)-1])+ if 2 <= len(e) && strings.HasPrefix(e, "/") && strings.HasSuffix(e, "/") {+ if re, err := regexp.Compile(e[1 : len(e)-1]); nil == err {+ regexps = append(regexps, re)+ }} else {tmp = append(tmp, e)}}excludes = tmp- ret = gulu.Str.ExcludeElem(ret, excludes)+ keywords = gulu.Str.ExcludeElem(keywords, excludes)if 0 < len(regexps) {tmp = nil- for _, str := range ret {+ for _, str := range keywords {matchExclude := falsefor _, re := range regexps {- if ok, _ := regexp.MatchString(re, str); ok {+ if re.MatchString(str) {matchExclude = truebreak}@@ -327,24 +350,10 @@ func getVirtualRefKeywords(root *ast.Node, boxIDs ...string) (ret []string) {tmp = append(tmp, str)}}- ret = tmp+ keywords = tmp}}-- // 虚拟引用排除当前文档名 https://github.com/siyuan-note/siyuan/issues/4537- // Virtual references exclude the name and aliases from the current document https://github.com/siyuan-note/siyuan/issues/9204- title := root.IALAttr("title")- ret = gulu.Str.ExcludeElem(ret, []string{title})- if name := root.IALAttr("name"); "" != name {- ret = gulu.Str.ExcludeElem(ret, []string{name})- }- if alias := root.IALAttr("alias"); "" != alias {- for a := range strings.SplitSeq(alias, ",") {- ret = gulu.Str.ExcludeElem(ret, []string{a})- }- }-- ret = prepareMarkKeywords(ret)+ ret = keywordsreturn}