|
@@ -41,6 +41,7 @@ import (
|
|
"github.com/emirpasic/gods/sets/hashset"
|
|
"github.com/emirpasic/gods/sets/hashset"
|
|
"github.com/emirpasic/gods/stacks/linkedliststack"
|
|
"github.com/emirpasic/gods/stacks/linkedliststack"
|
|
"github.com/siyuan-note/filelock"
|
|
"github.com/siyuan-note/filelock"
|
|
|
|
+ "github.com/siyuan-note/logging"
|
|
"github.com/siyuan-note/siyuan/kernel/sql"
|
|
"github.com/siyuan-note/siyuan/kernel/sql"
|
|
"github.com/siyuan-note/siyuan/kernel/treenode"
|
|
"github.com/siyuan-note/siyuan/kernel/treenode"
|
|
"github.com/siyuan-note/siyuan/kernel/util"
|
|
"github.com/siyuan-note/siyuan/kernel/util"
|
|
@@ -49,7 +50,7 @@ import (
|
|
func ExportSY(id string) (name, zipPath string) {
|
|
func ExportSY(id string) (name, zipPath string) {
|
|
block := treenode.GetBlockTree(id)
|
|
block := treenode.GetBlockTree(id)
|
|
if nil == block {
|
|
if nil == block {
|
|
- util.LogErrorf("not found block [%s]", id)
|
|
|
|
|
|
+ logging.LogErrorf("not found block [%s]", id)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -108,7 +109,7 @@ func ExportData() (zipPath string) {
|
|
func exportData(exportFolder string) (err error) {
|
|
func exportData(exportFolder string) (err error) {
|
|
baseFolderName := "data-" + util.CurrentTimeSecondsStr()
|
|
baseFolderName := "data-" + util.CurrentTimeSecondsStr()
|
|
if err = os.MkdirAll(exportFolder, 0755); nil != err {
|
|
if err = os.MkdirAll(exportFolder, 0755); nil != err {
|
|
- util.LogErrorf("create export temp folder failed: %s", err)
|
|
|
|
|
|
+ logging.LogErrorf("create export temp folder failed: %s", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -119,7 +120,7 @@ func exportData(exportFolder string) (err error) {
|
|
|
|
|
|
data := filepath.Join(util.WorkspaceDir, "data")
|
|
data := filepath.Join(util.WorkspaceDir, "data")
|
|
if err = stableCopy(data, exportFolder); nil != err {
|
|
if err = stableCopy(data, exportFolder); nil != err {
|
|
- util.LogErrorf("copy data dir from [%s] to [%s] failed: %s", data, baseFolderName, err)
|
|
|
|
|
|
+ logging.LogErrorf("copy data dir from [%s] to [%s] failed: %s", data, baseFolderName, err)
|
|
err = errors.New(fmt.Sprintf(Conf.Language(14), formatErrorMsg(err)))
|
|
err = errors.New(fmt.Sprintf(Conf.Language(14), formatErrorMsg(err)))
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -127,17 +128,17 @@ func exportData(exportFolder string) (err error) {
|
|
zipPath := exportFolder + ".zip"
|
|
zipPath := exportFolder + ".zip"
|
|
zip, err := gulu.Zip.Create(zipPath)
|
|
zip, err := gulu.Zip.Create(zipPath)
|
|
if nil != err {
|
|
if nil != err {
|
|
- util.LogErrorf("create export data zip [%s] failed: %s", exportFolder, err)
|
|
|
|
|
|
+ logging.LogErrorf("create export data zip [%s] failed: %s", exportFolder, err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
if err = zip.AddDirectory(baseFolderName, exportFolder); nil != err {
|
|
if err = zip.AddDirectory(baseFolderName, exportFolder); nil != err {
|
|
- util.LogErrorf("create export data zip [%s] failed: %s", exportFolder, err)
|
|
|
|
|
|
+ logging.LogErrorf("create export data zip [%s] failed: %s", exportFolder, err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
if err = zip.Close(); nil != err {
|
|
if err = zip.Close(); nil != err {
|
|
- util.LogErrorf("close export data zip failed: %s", err)
|
|
|
|
|
|
+ logging.LogErrorf("close export data zip failed: %s", err)
|
|
}
|
|
}
|
|
|
|
|
|
os.RemoveAll(exportFolder)
|
|
os.RemoveAll(exportFolder)
|
|
@@ -174,19 +175,19 @@ func ExportDocx(id, savePath string) (err error) {
|
|
pandoc.Stdin = bytes.NewBufferString(dom)
|
|
pandoc.Stdin = bytes.NewBufferString(dom)
|
|
output, err := pandoc.CombinedOutput()
|
|
output, err := pandoc.CombinedOutput()
|
|
if nil != err {
|
|
if nil != err {
|
|
- util.LogErrorf("export docx failed: %s", gulu.Str.FromBytes(output))
|
|
|
|
|
|
+ logging.LogErrorf("export docx failed: %s", gulu.Str.FromBytes(output))
|
|
msg := fmt.Sprintf(Conf.Language(14), gulu.Str.FromBytes(output))
|
|
msg := fmt.Sprintf(Conf.Language(14), gulu.Str.FromBytes(output))
|
|
return errors.New(msg)
|
|
return errors.New(msg)
|
|
}
|
|
}
|
|
|
|
|
|
if err = gulu.File.Copy(tmpDocxPath, filepath.Join(savePath, name+".docx")); nil != err {
|
|
if err = gulu.File.Copy(tmpDocxPath, filepath.Join(savePath, name+".docx")); nil != err {
|
|
- util.LogErrorf("export docx failed: %s", err)
|
|
|
|
|
|
+ logging.LogErrorf("export docx failed: %s", err)
|
|
return errors.New(fmt.Sprintf(Conf.Language(14), err))
|
|
return errors.New(fmt.Sprintf(Conf.Language(14), err))
|
|
}
|
|
}
|
|
tmpAssets := filepath.Join(tmpDir, "assets")
|
|
tmpAssets := filepath.Join(tmpDir, "assets")
|
|
if gulu.File.IsDir(tmpAssets) {
|
|
if gulu.File.IsDir(tmpAssets) {
|
|
if err = gulu.File.Copy(tmpAssets, filepath.Join(savePath, "assets")); nil != err {
|
|
if err = gulu.File.Copy(tmpAssets, filepath.Join(savePath, "assets")); nil != err {
|
|
- util.LogErrorf("export docx failed: %s", err)
|
|
|
|
|
|
+ logging.LogErrorf("export docx failed: %s", err)
|
|
return errors.New(fmt.Sprintf(Conf.Language(14), err))
|
|
return errors.New(fmt.Sprintf(Conf.Language(14), err))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -200,7 +201,7 @@ func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) {
|
|
name = path.Base(tree.HPath)
|
|
name = path.Base(tree.HPath)
|
|
|
|
|
|
if err := os.MkdirAll(savePath, 0755); nil != err {
|
|
if err := os.MkdirAll(savePath, 0755); nil != err {
|
|
- util.LogErrorf("mkdir [%s] failed: %s", savePath, err)
|
|
|
|
|
|
+ logging.LogErrorf("mkdir [%s] failed: %s", savePath, err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -209,12 +210,12 @@ func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) {
|
|
if strings.HasPrefix(asset, "assets/") {
|
|
if strings.HasPrefix(asset, "assets/") {
|
|
srcAbsPath, err := GetAssetAbsPath(asset)
|
|
srcAbsPath, err := GetAssetAbsPath(asset)
|
|
if nil != err {
|
|
if nil != err {
|
|
- util.LogWarnf("resolve path of asset [%s] failed: %s", asset, err)
|
|
|
|
|
|
+ logging.LogWarnf("resolve path of asset [%s] failed: %s", asset, err)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
targetAbsPath := filepath.Join(savePath, asset)
|
|
targetAbsPath := filepath.Join(savePath, asset)
|
|
if err = gulu.File.Copy(srcAbsPath, targetAbsPath); nil != err {
|
|
if err = gulu.File.Copy(srcAbsPath, targetAbsPath); nil != err {
|
|
- util.LogWarnf("copy asset from [%s] to [%s] failed: %s", srcAbsPath, targetAbsPath, err)
|
|
|
|
|
|
+ logging.LogWarnf("copy asset from [%s] to [%s] failed: %s", srcAbsPath, targetAbsPath, err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -224,7 +225,7 @@ func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) {
|
|
from := filepath.Join(util.WorkingDir, src)
|
|
from := filepath.Join(util.WorkingDir, src)
|
|
to := filepath.Join(savePath, src)
|
|
to := filepath.Join(savePath, src)
|
|
if err := gulu.File.Copy(from, to); nil != err {
|
|
if err := gulu.File.Copy(from, to); nil != err {
|
|
- util.LogWarnf("copy stage from [%s] to [%s] failed: %s", from, savePath, err)
|
|
|
|
|
|
+ logging.LogWarnf("copy stage from [%s] to [%s] failed: %s", from, savePath, err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -238,7 +239,7 @@ func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) {
|
|
from := filepath.Join(util.AppearancePath, src)
|
|
from := filepath.Join(util.AppearancePath, src)
|
|
to := filepath.Join(savePath, "appearance", src)
|
|
to := filepath.Join(savePath, "appearance", src)
|
|
if err := gulu.File.Copy(from, to); nil != err {
|
|
if err := gulu.File.Copy(from, to); nil != err {
|
|
- util.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err)
|
|
|
|
|
|
+ logging.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -283,7 +284,7 @@ func ExportHTML(id, savePath string, pdf bool) (name, dom string) {
|
|
name = path.Base(tree.Path)
|
|
name = path.Base(tree.Path)
|
|
|
|
|
|
if err := os.MkdirAll(savePath, 0755); nil != err {
|
|
if err := os.MkdirAll(savePath, 0755); nil != err {
|
|
- util.LogErrorf("mkdir [%s] failed: %s", savePath, err)
|
|
|
|
|
|
+ logging.LogErrorf("mkdir [%s] failed: %s", savePath, err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -291,12 +292,12 @@ func ExportHTML(id, savePath string, pdf bool) (name, dom string) {
|
|
for _, asset := range assets {
|
|
for _, asset := range assets {
|
|
srcAbsPath, err := GetAssetAbsPath(asset)
|
|
srcAbsPath, err := GetAssetAbsPath(asset)
|
|
if nil != err {
|
|
if nil != err {
|
|
- util.LogWarnf("resolve path of asset [%s] failed: %s", asset, err)
|
|
|
|
|
|
+ logging.LogWarnf("resolve path of asset [%s] failed: %s", asset, err)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
targetAbsPath := filepath.Join(savePath, asset)
|
|
targetAbsPath := filepath.Join(savePath, asset)
|
|
if err = gulu.File.Copy(srcAbsPath, targetAbsPath); nil != err {
|
|
if err = gulu.File.Copy(srcAbsPath, targetAbsPath); nil != err {
|
|
- util.LogWarnf("copy asset from [%s] to [%s] failed: %s", srcAbsPath, targetAbsPath, err)
|
|
|
|
|
|
+ logging.LogWarnf("copy asset from [%s] to [%s] failed: %s", srcAbsPath, targetAbsPath, err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -307,7 +308,7 @@ func ExportHTML(id, savePath string, pdf bool) (name, dom string) {
|
|
from := filepath.Join(util.WorkingDir, src)
|
|
from := filepath.Join(util.WorkingDir, src)
|
|
to := filepath.Join(savePath, src)
|
|
to := filepath.Join(savePath, src)
|
|
if err := gulu.File.Copy(from, to); nil != err {
|
|
if err := gulu.File.Copy(from, to); nil != err {
|
|
- util.LogErrorf("copy stage from [%s] to [%s] failed: %s", from, savePath, err)
|
|
|
|
|
|
+ logging.LogErrorf("copy stage from [%s] to [%s] failed: %s", from, savePath, err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -321,7 +322,7 @@ func ExportHTML(id, savePath string, pdf bool) (name, dom string) {
|
|
from := filepath.Join(util.AppearancePath, src)
|
|
from := filepath.Join(util.AppearancePath, src)
|
|
to := filepath.Join(savePath, "appearance", src)
|
|
to := filepath.Join(savePath, "appearance", src)
|
|
if err := gulu.File.Copy(from, to); nil != err {
|
|
if err := gulu.File.Copy(from, to); nil != err {
|
|
- util.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err)
|
|
|
|
|
|
+ logging.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -444,7 +445,7 @@ func AddPDFOutline(id, p string) (err error) {
|
|
outFile := inFile + ".tmp"
|
|
outFile := inFile + ".tmp"
|
|
err = api.AddBookmarksFile(inFile, outFile, topBms, nil)
|
|
err = api.AddBookmarksFile(inFile, outFile, topBms, nil)
|
|
if nil != err {
|
|
if nil != err {
|
|
- util.LogErrorf("add bookmark failed: %s", err)
|
|
|
|
|
|
+ logging.LogErrorf("add bookmark failed: %s", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
err = os.Rename(outFile, inFile)
|
|
err = os.Rename(outFile, inFile)
|
|
@@ -467,7 +468,7 @@ func CopyStdMarkdown(id string) string {
|
|
func ExportMarkdown(id string) (name, zipPath string) {
|
|
func ExportMarkdown(id string) (name, zipPath string) {
|
|
block := treenode.GetBlockTree(id)
|
|
block := treenode.GetBlockTree(id)
|
|
if nil == block {
|
|
if nil == block {
|
|
- util.LogErrorf("not found block [%s]", id)
|
|
|
|
|
|
+ logging.LogErrorf("not found block [%s]", id)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -496,7 +497,7 @@ func BatchExportMarkdown(boxID, folderPath string) (zipPath string) {
|
|
} else {
|
|
} else {
|
|
block := treenode.GetBlockTreeRootByHPath(box.ID, folderPath)
|
|
block := treenode.GetBlockTreeRootByHPath(box.ID, folderPath)
|
|
if nil == block {
|
|
if nil == block {
|
|
- util.LogErrorf("not found block")
|
|
|
|
|
|
+ logging.LogErrorf("not found block")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
baseFolderName = path.Base(block.HPath)
|
|
baseFolderName = path.Base(block.HPath)
|
|
@@ -527,7 +528,7 @@ func exportMarkdownZip(boxID, baseFolderName string, docPaths []string) (zipPath
|
|
|
|
|
|
exportFolder := filepath.Join(util.TempDir, "export", baseFolderName)
|
|
exportFolder := filepath.Join(util.TempDir, "export", baseFolderName)
|
|
if err := os.MkdirAll(exportFolder, 0755); nil != err {
|
|
if err := os.MkdirAll(exportFolder, 0755); nil != err {
|
|
- util.LogErrorf("create export temp folder failed: %s", err)
|
|
|
|
|
|
+ logging.LogErrorf("create export temp folder failed: %s", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -553,11 +554,11 @@ func exportMarkdownZip(boxID, baseFolderName string, docPaths []string) (zipPath
|
|
}
|
|
}
|
|
writeFolder := filepath.Dir(writePath)
|
|
writeFolder := filepath.Dir(writePath)
|
|
if err := os.MkdirAll(writeFolder, 0755); nil != err {
|
|
if err := os.MkdirAll(writeFolder, 0755); nil != err {
|
|
- util.LogErrorf("create export temp folder [%s] failed: %s", writeFolder, err)
|
|
|
|
|
|
+ logging.LogErrorf("create export temp folder [%s] failed: %s", writeFolder, err)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
if err := gulu.File.WriteFileSafer(writePath, gulu.Str.ToBytes(md), 0644); nil != err {
|
|
if err := gulu.File.WriteFileSafer(writePath, gulu.Str.ToBytes(md), 0644); nil != err {
|
|
- util.LogErrorf("write export markdown file [%s] failed: %s", writePath, err)
|
|
|
|
|
|
+ logging.LogErrorf("write export markdown file [%s] failed: %s", writePath, err)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
@@ -573,7 +574,7 @@ func exportMarkdownZip(boxID, baseFolderName string, docPaths []string) (zipPath
|
|
|
|
|
|
srcPath, err := GetAssetAbsPath(asset)
|
|
srcPath, err := GetAssetAbsPath(asset)
|
|
if nil != err {
|
|
if nil != err {
|
|
- util.LogWarnf("get asset [%s] abs path failed: %s", asset, err)
|
|
|
|
|
|
+ logging.LogWarnf("get asset [%s] abs path failed: %s", asset, err)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
@@ -584,7 +585,7 @@ func exportMarkdownZip(boxID, baseFolderName string, docPaths []string) (zipPath
|
|
err = gulu.File.CopyFile(srcPath, destPath)
|
|
err = gulu.File.CopyFile(srcPath, destPath)
|
|
}
|
|
}
|
|
if nil != err {
|
|
if nil != err {
|
|
- util.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, err)
|
|
|
|
|
|
+ logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, err)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -593,17 +594,17 @@ func exportMarkdownZip(boxID, baseFolderName string, docPaths []string) (zipPath
|
|
zipPath = exportFolder + ".zip"
|
|
zipPath = exportFolder + ".zip"
|
|
zip, err := gulu.Zip.Create(zipPath)
|
|
zip, err := gulu.Zip.Create(zipPath)
|
|
if nil != err {
|
|
if nil != err {
|
|
- util.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
|
|
|
|
|
+ logging.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
|
return ""
|
|
return ""
|
|
}
|
|
}
|
|
|
|
|
|
if err = zip.AddDirectory(baseFolderName, exportFolder); nil != err {
|
|
if err = zip.AddDirectory(baseFolderName, exportFolder); nil != err {
|
|
- util.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
|
|
|
|
|
+ logging.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
|
return ""
|
|
return ""
|
|
}
|
|
}
|
|
|
|
|
|
if err = zip.Close(); nil != err {
|
|
if err = zip.Close(); nil != err {
|
|
- util.LogErrorf("close export markdown zip failed: %s", err)
|
|
|
|
|
|
+ logging.LogErrorf("close export markdown zip failed: %s", err)
|
|
}
|
|
}
|
|
|
|
|
|
os.RemoveAll(exportFolder)
|
|
os.RemoveAll(exportFolder)
|
|
@@ -624,7 +625,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|
|
|
|
|
exportFolder := filepath.Join(util.TempDir, "export", baseFolderName)
|
|
exportFolder := filepath.Join(util.TempDir, "export", baseFolderName)
|
|
if err := os.MkdirAll(exportFolder, 0755); nil != err {
|
|
if err := os.MkdirAll(exportFolder, 0755); nil != err {
|
|
- util.LogErrorf("create export temp folder failed: %s", err)
|
|
|
|
|
|
+ logging.LogErrorf("create export temp folder failed: %s", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -657,7 +658,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|
readPath := filepath.Join(util.DataDir, tree.Box, tree.Path)
|
|
readPath := filepath.Join(util.DataDir, tree.Box, tree.Path)
|
|
data, readErr := filelock.NoLockFileRead(readPath)
|
|
data, readErr := filelock.NoLockFileRead(readPath)
|
|
if nil != readErr {
|
|
if nil != readErr {
|
|
- util.LogErrorf("read file [%s] failed: %s", readPath, readErr)
|
|
|
|
|
|
+ logging.LogErrorf("read file [%s] failed: %s", readPath, readErr)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
@@ -665,11 +666,11 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|
writePath = filepath.Join(exportFolder, writePath)
|
|
writePath = filepath.Join(exportFolder, writePath)
|
|
writeFolder := filepath.Dir(writePath)
|
|
writeFolder := filepath.Dir(writePath)
|
|
if mkdirErr := os.MkdirAll(writeFolder, 0755); nil != mkdirErr {
|
|
if mkdirErr := os.MkdirAll(writeFolder, 0755); nil != mkdirErr {
|
|
- util.LogErrorf("create export temp folder [%s] failed: %s", writeFolder, mkdirErr)
|
|
|
|
|
|
+ logging.LogErrorf("create export temp folder [%s] failed: %s", writeFolder, mkdirErr)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
if writeErr := os.WriteFile(writePath, data, 0644); nil != writeErr {
|
|
if writeErr := os.WriteFile(writePath, data, 0644); nil != writeErr {
|
|
- util.LogErrorf("write export file [%s] failed: %s", writePath, writeErr)
|
|
|
|
|
|
+ logging.LogErrorf("write export file [%s] failed: %s", writePath, writeErr)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -679,14 +680,14 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|
readPath := filepath.Join(util.DataDir, tree.Box, tree.Path)
|
|
readPath := filepath.Join(util.DataDir, tree.Box, tree.Path)
|
|
data, readErr := filelock.NoLockFileRead(readPath)
|
|
data, readErr := filelock.NoLockFileRead(readPath)
|
|
if nil != readErr {
|
|
if nil != readErr {
|
|
- util.LogErrorf("read file [%s] failed: %s", readPath, readErr)
|
|
|
|
|
|
+ logging.LogErrorf("read file [%s] failed: %s", readPath, readErr)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
writePath := strings.TrimPrefix(tree.Path, rootDirPath)
|
|
writePath := strings.TrimPrefix(tree.Path, rootDirPath)
|
|
writePath = filepath.Join(exportFolder, treeID+".sy")
|
|
writePath = filepath.Join(exportFolder, treeID+".sy")
|
|
if writeErr := os.WriteFile(writePath, data, 0644); nil != writeErr {
|
|
if writeErr := os.WriteFile(writePath, data, 0644); nil != writeErr {
|
|
- util.LogErrorf("write export file [%s] failed: %s", writePath, writeErr)
|
|
|
|
|
|
+ logging.LogErrorf("write export file [%s] failed: %s", writePath, writeErr)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -713,7 +714,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|
|
|
|
|
srcPath, assetErr := GetAssetAbsPath(asset)
|
|
srcPath, assetErr := GetAssetAbsPath(asset)
|
|
if nil != assetErr {
|
|
if nil != assetErr {
|
|
- util.LogWarnf("get asset [%s] abs path failed: %s", asset, assetErr)
|
|
|
|
|
|
+ logging.LogWarnf("get asset [%s] abs path failed: %s", asset, assetErr)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
@@ -724,7 +725,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|
assetErr = gulu.File.CopyFile(srcPath, destPath)
|
|
assetErr = gulu.File.CopyFile(srcPath, destPath)
|
|
}
|
|
}
|
|
if nil != assetErr {
|
|
if nil != assetErr {
|
|
- util.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, assetErr)
|
|
|
|
|
|
+ logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, assetErr)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
@@ -735,17 +736,17 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|
zipPath = exportFolder + ".sy.zip"
|
|
zipPath = exportFolder + ".sy.zip"
|
|
zip, err := gulu.Zip.Create(zipPath)
|
|
zip, err := gulu.Zip.Create(zipPath)
|
|
if nil != err {
|
|
if nil != err {
|
|
- util.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
|
|
|
|
|
+ logging.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
|
return ""
|
|
return ""
|
|
}
|
|
}
|
|
|
|
|
|
if err = zip.AddDirectory(baseFolderName, exportFolder); nil != err {
|
|
if err = zip.AddDirectory(baseFolderName, exportFolder); nil != err {
|
|
- util.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
|
|
|
|
|
+ logging.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
|
return ""
|
|
return ""
|
|
}
|
|
}
|
|
|
|
|
|
if err = zip.Close(); nil != err {
|
|
if err = zip.Close(); nil != err {
|
|
- util.LogErrorf("close export markdown zip failed: %s", err)
|
|
|
|
|
|
+ logging.LogErrorf("close export markdown zip failed: %s", err)
|
|
}
|
|
}
|
|
|
|
|
|
os.RemoveAll(exportFolder)
|
|
os.RemoveAll(exportFolder)
|
|
@@ -987,24 +988,24 @@ func exportTree(tree *parse.Tree, wysiwyg bool) (ret *parse.Tree) {
|
|
p := refID[:strings.LastIndex(refID, "/")]
|
|
p := refID[:strings.LastIndex(refID, "/")]
|
|
absPath, err := GetAssetAbsPath(p)
|
|
absPath, err := GetAssetAbsPath(p)
|
|
if nil != err {
|
|
if nil != err {
|
|
- util.LogWarnf("get assets abs path by rel path [%s] failed: %s", p, err)
|
|
|
|
|
|
+ logging.LogWarnf("get assets abs path by rel path [%s] failed: %s", p, err)
|
|
return ast.WalkSkipChildren
|
|
return ast.WalkSkipChildren
|
|
}
|
|
}
|
|
sya := absPath + ".sya"
|
|
sya := absPath + ".sya"
|
|
syaData, err := os.ReadFile(sya)
|
|
syaData, err := os.ReadFile(sya)
|
|
if nil != err {
|
|
if nil != err {
|
|
- util.LogErrorf("read file [%s] failed: %s", sya, err)
|
|
|
|
|
|
+ logging.LogErrorf("read file [%s] failed: %s", sya, err)
|
|
return ast.WalkSkipChildren
|
|
return ast.WalkSkipChildren
|
|
}
|
|
}
|
|
syaJSON := map[string]interface{}{}
|
|
syaJSON := map[string]interface{}{}
|
|
if err = gulu.JSON.UnmarshalJSON(syaData, &syaJSON); nil != err {
|
|
if err = gulu.JSON.UnmarshalJSON(syaData, &syaJSON); nil != err {
|
|
- util.LogErrorf("unmarshal file [%s] failed: %s", sya, err)
|
|
|
|
|
|
+ logging.LogErrorf("unmarshal file [%s] failed: %s", sya, err)
|
|
return ast.WalkSkipChildren
|
|
return ast.WalkSkipChildren
|
|
}
|
|
}
|
|
annotationID := refID[strings.LastIndex(refID, "/")+1:]
|
|
annotationID := refID[strings.LastIndex(refID, "/")+1:]
|
|
annotationData := syaJSON[annotationID]
|
|
annotationData := syaJSON[annotationID]
|
|
if nil == annotationData {
|
|
if nil == annotationData {
|
|
- util.LogErrorf("not found annotation [%s] in .sya", annotationID)
|
|
|
|
|
|
+ logging.LogErrorf("not found annotation [%s] in .sya", annotationID)
|
|
return ast.WalkSkipChildren
|
|
return ast.WalkSkipChildren
|
|
}
|
|
}
|
|
pages := annotationData.(map[string]interface{})["pages"].([]interface{})
|
|
pages := annotationData.(map[string]interface{})["pages"].([]interface{})
|
|
@@ -1293,7 +1294,7 @@ func collectFootnotesDefs(id string, refFootnotes *[]*refAsFootnotes, treeCache
|
|
}
|
|
}
|
|
node := treenode.GetNodeInTree(t, b.ID)
|
|
node := treenode.GetNodeInTree(t, b.ID)
|
|
if nil == node {
|
|
if nil == node {
|
|
- util.LogErrorf("not found node [%s] in tree [%s]", b.ID, t.Root.ID)
|
|
|
|
|
|
+ logging.LogErrorf("not found node [%s] in tree [%s]", b.ID, t.Root.ID)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
collectFootnotesDefs0(node, refFootnotes, treeCache, depth)
|
|
collectFootnotesDefs0(node, refFootnotes, treeCache, depth)
|