mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Improve exporting .sy.zip https://github.com/siyuan-note/siyuan/issues/13011
This commit is contained in:
parent
40cbf3c8c3
commit
a547bb7da2
3 changed files with 16 additions and 20 deletions
|
|
@ -1001,7 +1001,7 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {
|
||||||
k := kv[0]
|
k := kv[0]
|
||||||
if strings.HasPrefix(k, "custom-data-assets") {
|
if strings.HasPrefix(k, "custom-data-assets") {
|
||||||
dest := kv[1]
|
dest := kv[1]
|
||||||
if "" == dest || !treenode.IsRelativePath([]byte(dest)) {
|
if "" == dest || !util.IsAssetLinkDest([]byte(dest)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ret = append(ret, dest)
|
ret = append(ret, dest)
|
||||||
|
|
@ -1017,21 +1017,21 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ast.NodeLinkDest == n.Type {
|
if ast.NodeLinkDest == n.Type {
|
||||||
if !treenode.IsRelativePath(n.Tokens) {
|
if !util.IsAssetLinkDest(n.Tokens) {
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
dest := strings.TrimSpace(string(n.Tokens))
|
dest := strings.TrimSpace(string(n.Tokens))
|
||||||
ret = append(ret, dest)
|
ret = append(ret, dest)
|
||||||
} else if n.IsTextMarkType("a") {
|
} else if n.IsTextMarkType("a") {
|
||||||
if !treenode.IsRelativePath(gulu.Str.ToBytes(n.TextMarkAHref)) {
|
if !util.IsAssetLinkDest(gulu.Str.ToBytes(n.TextMarkAHref)) {
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
dest := strings.TrimSpace(n.TextMarkAHref)
|
dest := strings.TrimSpace(n.TextMarkAHref)
|
||||||
ret = append(ret, dest)
|
ret = append(ret, dest)
|
||||||
} else if n.IsTextMarkType("file-annotation-ref") {
|
} 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
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1057,7 +1057,7 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {
|
||||||
|
|
||||||
for _, asset := range value.MAsset {
|
for _, asset := range value.MAsset {
|
||||||
dest := asset.Content
|
dest := asset.Content
|
||||||
if !treenode.IsRelativePath([]byte(dest)) {
|
if !util.IsAssetLinkDest([]byte(dest)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1068,7 +1068,7 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {
|
||||||
for _, value := range keyValues.Values {
|
for _, value := range keyValues.Values {
|
||||||
if nil != value.URL {
|
if nil != value.URL {
|
||||||
dest := value.URL.Content
|
dest := value.URL.Content
|
||||||
if !treenode.IsRelativePath([]byte(dest)) {
|
if !util.IsAssetLinkDest([]byte(dest)) {
|
||||||
continue
|
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
|
// 兼容两种属性名 custom-data-assets 和 data-assets https://github.com/siyuan-note/siyuan/issues/4122#issuecomment-1154796568
|
||||||
dataAssets = n.IALAttr("data-assets")
|
dataAssets = n.IALAttr("data-assets")
|
||||||
}
|
}
|
||||||
if "" == dataAssets || !treenode.IsRelativePath([]byte(dataAssets)) {
|
if "" == dataAssets || !util.IsAssetLinkDest([]byte(dataAssets)) {
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
ret = append(ret, dataAssets)
|
ret = append(ret, dataAssets)
|
||||||
|
|
|
||||||
|
|
@ -1536,6 +1536,10 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
||||||
refTrees := map[string]*parse.Tree{}
|
refTrees := map[string]*parse.Tree{}
|
||||||
luteEngine := util.NewLute()
|
luteEngine := util.NewLute()
|
||||||
for i, p := range docPaths {
|
for i, p := range docPaths {
|
||||||
|
if !strings.HasSuffix(p, ".sy") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
tree, err := filesys.LoadTree(boxID, p, luteEngine)
|
tree, err := filesys.LoadTree(boxID, p, luteEngine)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
|
@ -1622,7 +1626,9 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
||||||
assets = append(assets, assetsLinkDestsInTree(tree)...)
|
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
|
titleImgPath := treenode.GetDocTitleImgPath(tree.Root) // Export .sy.zip doc title image is not exported https://github.com/siyuan-note/siyuan/issues/8748
|
||||||
if "" != titleImgPath {
|
if "" != titleImgPath {
|
||||||
assets = append(assets, titleImgPath)
|
if util.IsAssetLinkDest([]byte(titleImgPath)) {
|
||||||
|
assets = append(assets, titleImgPath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, asset := range assets {
|
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
|
case av.KeyTypeMAsset: // 导出资源文件列 https://github.com/siyuan-note/siyuan/issues/9919
|
||||||
for _, value := range keyValues.Values {
|
for _, value := range keyValues.Values {
|
||||||
for _, asset := range value.MAsset {
|
for _, asset := range value.MAsset {
|
||||||
if !treenode.IsRelativePath([]byte(asset.Content)) {
|
if !util.IsAssetLinkDest([]byte(asset.Content)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ func GetNodeSrcTokens(n *ast.Node) (ret string) {
|
||||||
src := n.Tokens[index+len("src=\""):]
|
src := n.Tokens[index+len("src=\""):]
|
||||||
if index = bytes.Index(src, []byte("\"")); 0 < index {
|
if index = bytes.Index(src, []byte("\"")); 0 < index {
|
||||||
src = src[:bytes.Index(src, []byte("\""))]
|
src = src[:bytes.Index(src, []byte("\""))]
|
||||||
if !IsRelativePath(src) {
|
if !util.IsAssetLinkDest(src) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -182,16 +182,6 @@ func GetNodeSrcTokens(n *ast.Node) (ret string) {
|
||||||
return
|
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) {
|
func FirstLeafBlock(node *ast.Node) (ret *ast.Node) {
|
||||||
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
if !entering || n.IsMarker() {
|
if !entering || n.IsMarker() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue