Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve exporting .sy.zip https://github.com/siyuan-note/siyuan/issues/13011

Daniela547bb7da284
diff --git a/kernel/model/assets.go b/kernel/model/assets.go
index e21046a33c..d2050f959c 100644
--- a/kernel/model/assets.go
+++ b/kernel/model/assets.go
@@ -1001,7 +1001,7 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {
k := kv[0]
if strings.HasPrefix(k, "custom-data-assets") {
dest := kv[1]
- if "" == dest || !treenode.IsRelativePath([]byte(dest)) {
+ if "" == dest || !util.IsAssetLinkDest([]byte(dest)) {
continue
}
ret = append(ret, dest)
@@ -1017,21 +1017,21 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {
}
if ast.NodeLinkDest == n.Type {
- if !treenode.IsRelativePath(n.Tokens) {
+ if !util.IsAssetLinkDest(n.Tokens) {
return ast.WalkContinue
}
dest := strings.TrimSpace(string(n.Tokens))
ret = append(ret, dest)
} else if n.IsTextMarkType("a") {
- if !treenode.IsRelativePath(gulu.Str.ToBytes(n.TextMarkAHref)) {
+ if !util.IsAssetLinkDest(gulu.Str.ToBytes(n.TextMarkAHref)) {
return ast.WalkContinue
}
dest := strings.TrimSpace(n.TextMarkAHref)
ret = append(ret, dest)
} else if n.IsTextMarkType("file-annotation-ref") {
- if !treenode.IsRelativePath(gulu.Str.ToBytes(n.TextMarkFileAnnotationRefID)) {
+ if !util.IsAssetLinkDest(gulu.Str.ToBytes(n.TextMarkFileAnnotationRefID)) {
return ast.WalkContinue
}
@@ -1057,7 +1057,7 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {
for _, asset := range value.MAsset {
dest := asset.Content
- if !treenode.IsRelativePath([]byte(dest)) {
+ if !util.IsAssetLinkDest([]byte(dest)) {
continue
}
@@ -1068,7 +1068,7 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {
for _, value := range keyValues.Values {
if nil != value.URL {
dest := value.URL.Content
- if !treenode.IsRelativePath([]byte(dest)) {
+ if !util.IsAssetLinkDest([]byte(dest)) {
continue
}
@@ -1085,7 +1085,7 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {
// 兼容两种属性名 custom-data-assets 和 data-assets https://github.com/siyuan-note/siyuan/issues/4122#issuecomment-1154796568
dataAssets = n.IALAttr("data-assets")
}
- if "" == dataAssets || !treenode.IsRelativePath([]byte(dataAssets)) {
+ if "" == dataAssets || !util.IsAssetLinkDest([]byte(dataAssets)) {
return ast.WalkContinue
}
ret = append(ret, dataAssets)
diff --git a/kernel/model/export.go b/kernel/model/export.go
index bbaef5aee5..63b34a5a09 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -1536,6 +1536,10 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
refTrees := map[string]*parse.Tree{}
luteEngine := util.NewLute()
for i, p := range docPaths {
+ if !strings.HasSuffix(p, ".sy") {
+ continue
+ }
+
tree, err := filesys.LoadTree(boxID, p, luteEngine)
if err != nil {
continue
@@ -1622,7 +1626,9 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
assets = append(assets, assetsLinkDestsInTree(tree)...)
titleImgPath := treenode.GetDocTitleImgPath(tree.Root) // Export .sy.zip doc title image is not exported https://github.com/siyuan-note/siyuan/issues/8748
if "" != titleImgPath {
- assets = append(assets, titleImgPath)
+ if util.IsAssetLinkDest([]byte(titleImgPath)) {
+ assets = append(assets, titleImgPath)
+ }
}
for _, asset := range assets {
@@ -1697,7 +1703,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
case av.KeyTypeMAsset: // 导出资源文件列 https://github.com/siyuan-note/siyuan/issues/9919
for _, value := range keyValues.Values {
for _, asset := range value.MAsset {
- if !treenode.IsRelativePath([]byte(asset.Content)) {
+ if !util.IsAssetLinkDest([]byte(asset.Content)) {
continue
}
diff --git a/kernel/treenode/node.go b/kernel/treenode/node.go
index 98ce2a8794..c58d3a9ecd 100644
--- a/kernel/treenode/node.go
+++ b/kernel/treenode/node.go
@@ -169,7 +169,7 @@ func GetNodeSrcTokens(n *ast.Node) (ret string) {
src := n.Tokens[index+len("src=\""):]
if index = bytes.Index(src, []byte("\"")); 0 < index {
src = src[:bytes.Index(src, []byte("\""))]
- if !IsRelativePath(src) {
+ if !util.IsAssetLinkDest(src) {
return
}
@@ -182,16 +182,6 @@ func GetNodeSrcTokens(n *ast.Node) (ret string) {
return
}
-func IsRelativePath(dest []byte) bool {
- if 1 > len(dest) {
- return false
- }
- if '/' == dest[0] {
- return false
- }
- return !bytes.Contains(dest, []byte(":"))
-}
-
func FirstLeafBlock(node *ast.Node) (ret *ast.Node) {
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || n.IsMarker() {