Skip to content

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

:art: Improve exporting markdown https://github.com/siyuan-note/siyuan/issues/13500

Daniel7395554ebe0e
diff --git a/kernel/model/export.go b/kernel/model/export.go
index da4d2d47e8..586dbef32e 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -18,6 +18,7 @@ package model
import (
"bytes"
+ "crypto/sha1"
"encoding/csv"
"errors"
"fmt"
@@ -3086,6 +3087,8 @@ func processFileAnnotationRef(refID string, n *ast.Node, fileAnnotationRefMode i
func exportPandocConvertZip(baseFolderName string, docPaths []string,
pandocFrom, pandocTo, ext string) (zipPath string) {
+ defer util.ClearPushProgress(100)
+
dir, name := path.Split(baseFolderName)
name = util.FilterFileName(name)
if strings.HasSuffix(name, "..") {
@@ -3146,8 +3149,10 @@ func exportPandocConvertZip(baseFolderName string, docPaths []string,
docPaths = gulu.Str.RemoveDuplicatedElem(docPaths)
}
+ wrotePathHash := map[string]string{}
+
luteEngine := util.NewLute()
- for _, p := range docPaths {
+ for i, p := range docPaths {
id := util.GetTreeID(p)
hPath, md := exportMarkdownContent(id, exportRefMode, defBlockIDs)
dir, name = path.Split(hPath)
@@ -3156,7 +3161,8 @@ func exportPandocConvertZip(baseFolderName string, docPaths []string,
hPath = path.Join(dir, name)
p = hPath + ext
writePath := filepath.Join(exportFolder, p)
- if gulu.File.IsExist(writePath) {
+ hash := fmt.Sprintf("%x", sha1.Sum([]byte(md)))
+ if gulu.File.IsExist(writePath) && hash != wrotePathHash[writePath] {
// 重名文档加 ID
p = hPath + "-" + id + ext
writePath = filepath.Join(exportFolder, p)
@@ -3201,6 +3207,9 @@ func exportPandocConvertZip(baseFolderName string, docPaths []string,
logging.LogErrorf("pandoc failed: %s", err)
continue
}
+
+ wrotePathHash[writePath] = hash
+ util.PushEndlessProgress(Conf.language(65) + " " + fmt.Sprintf(Conf.language(70), fmt.Sprintf("%d/%d %s", i+1, len(docPaths), name)))
}
zipPath = exportFolder + ".zip"