From 7395554ebe0ea7786021677418491c510aaab3da Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 16 Dec 2024 22:50:55 +0800 Subject: [PATCH] :art: Improve exporting markdown https://github.com/siyuan-note/siyuan/issues/13500 --- kernel/model/export.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kernel/model/export.go b/kernel/model/export.go index da4d2d47e..586dbef32 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"