From 150aa2a7bf83a6eb0164f396e1bcf8a4649573fc Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 24 Sep 2024 23:20:22 +0800 Subject: [PATCH] :art: Ignore assets associated with the `custom-data-assets` block attribute when cleaning unreferenced assets https://github.com/siyuan-note/siyuan/issues/12574 --- kernel/model/assets.go | 15 +++++++++++++++ kernel/sql/database.go | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 34f67ccd6..df7b8aaa8 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -992,6 +992,21 @@ func assetsLinkDestsInTree(tree *parse.Tree) (ret []string) { func assetsLinkDestsInNode(node *ast.Node) (ret []string) { ret = []string{} ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus { + if n.IsBlock() { + // 以 custom-data-assets 开头的块属性值可能是多个资源文件链接,需要计入 + // Ignore assets associated with the `custom-data-assets` block attribute when cleaning unreferenced assets https://github.com/siyuan-note/siyuan/issues/12574 + for _, kv := range n.KramdownIAL { + k := kv[0] + if strings.HasPrefix(k, "custom-data-assets") { + dest := kv[1] + if "" == dest || !treenode.IsRelativePath([]byte(dest)) { + continue + } + ret = append(ret, dest) + } + } + } + // 修改以下代码时需要同时修改 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 && diff --git a/kernel/sql/database.go b/kernel/sql/database.go index fb454bd04..07828a2ea 100644 --- a/kernel/sql/database.go +++ b/kernel/sql/database.go @@ -752,7 +752,7 @@ func buildSpanFromNode(n *ast.Node, tree *parse.Tree, rootID, boxID, p string) ( var src []byte for _, attr := range nodes[0].Attr { - if "src" == attr.Key || "data-assets" == attr.Key || "custom-data-assets" == attr.Key { + if "src" == attr.Key || strings.HasPrefix(attr.Key, "data-assets") || strings.HasPrefix(attr.Key, "custom-data-assets") { src = gulu.Str.ToBytes(attr.Val) break }