An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improved PDF asset file unreferenced detection https://github.com/siyuan-note/siyuan/issues/7964
Liang Ding204c3b469da8
diff --git a/kernel/model/assets.go b/kernel/model/assets.goindex 5eced62d42..1ec8c338c1 100644--- a/kernel/model/assets.go+++ b/kernel/model/assets.go@@ -634,17 +634,15 @@ func UnusedAssets() (ret []string) {for _, dest := range linkDestFilePaths {linkDestMap[dest] = true++ if strings.HasSuffix(dest, ".pdf") {+ linkDestMap[dest+".sya"] = true+ }}}var toRemoves []stringfor asset, _ := range assetsPathMap {- if strings.HasSuffix(asset, ".sya") {- // 排除文件注解和对应文件- toRemoves = append(toRemoves, asset, strings.TrimSuffix(asset, ".sya"))- continue- }-if strings.HasSuffix(asset, "ocr-texts.json") {// 排除 OCR 结果文本toRemoves = append(toRemoves, asset)@@ -656,8 +654,8 @@ func UnusedAssets() (ret []string) {}dataAssetsAbsPath := util.GetDataAssetsAbsPath()- for _, assetAbsPath := range assetsPathMap {- if _, ok := linkDestMap[assetAbsPath]; ok {+ for dest, assetAbsPath := range assetsPathMap {+ if _, ok := linkDestMap[dest]; ok {continue}@@ -704,7 +702,7 @@ func assetsLinkDestsInTree(tree *parse.Tree) (ret []string) {// 修改以下代码时需要同时修改 database 构造行级元素实现,增加必要的类型if !entering || (ast.NodeLinkDest != n.Type && ast.NodeHTMLBlock != n.Type && ast.NodeInlineHTML != n.Type &&ast.NodeIFrame != n.Type && ast.NodeWidget != n.Type && ast.NodeAudio != n.Type && ast.NodeVideo != n.Type &&- !n.IsTextMarkType("a")) {+ !n.IsTextMarkType("a") && !n.IsTextMarkType("file-annotation-ref")) {return ast.WalkContinue}@@ -722,6 +720,14 @@ func assetsLinkDestsInTree(tree *parse.Tree) (ret []string) {dest := strings.TrimSpace(n.TextMarkAHref)ret = append(ret, dest)+ } else if n.IsTextMarkType("file-annotation-ref") {+ if !isRelativePath(gulu.Str.ToBytes(n.TextMarkFileAnnotationRefID)) {+ return ast.WalkContinue+ }++ dest := n.TextMarkFileAnnotationRefID[:strings.LastIndexByte(n.TextMarkFileAnnotationRefID, '/')]+ dest = strings.TrimSpace(dest)+ ret = append(ret, dest)} else {if ast.NodeWidget == n.Type {dataAssets := n.IALAttr("custom-data-assets")@@ -752,6 +758,7 @@ func assetsLinkDestsInTree(tree *parse.Tree) (ret []string) {}return ast.WalkContinue})+ ret = gulu.Str.RemoveDuplicatedElem(ret)return}diff --git a/kernel/model/export.go b/kernel/model/export.goindex 98237f737d..55eedcac4a 100644--- a/kernel/model/export.go+++ b/kernel/model/export.go@@ -403,6 +403,10 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom stringassets := assetsLinkDestsInTree(tree)for _, asset := range assets {if strings.HasPrefix(asset, "assets/") {+ if strings.Contains(asset, "?") {+ asset = asset[:strings.LastIndex(asset, "?")]+ }+srcAbsPath, err := GetAssetAbsPath(asset)if nil != err {logging.LogWarnf("resolve path of asset [%s] failed: %s", asset, err)