浏览代码

Merge remote-tracking branch 'origin/dev' into dev

Vanessa 1 年之前
父节点
当前提交
bb1314c66f
共有 3 个文件被更改,包括 26 次插入9 次删除
  1. 1 3
      app/electron-builder-arm64.yml
  2. 1 3
      app/electron-builder-linux-arm64.yml
  3. 24 3
      kernel/util/pandoc.go

+ 1 - 3
app/electron-builder-arm64.yml

@@ -70,6 +70,4 @@ extraResources:
     filter: "!**/{.DS_Store,custom.css}"
   - from: "src/assets/fonts"
     to: "appearance/fonts"
-    filter: "!**/{.DS_Store}"
-  - from: "pandoc/pandoc-windows-amd64.zip"
-    to: "pandoc.zip"
+    filter: "!**/{.DS_Store}"

+ 1 - 3
app/electron-builder-linux-arm64.yml

@@ -63,6 +63,4 @@ extraResources:
     filter: "!**/{.DS_Store,custom.css}"
   - from: "src/assets/fonts"
     to: "appearance/fonts"
-    filter: "!**/{.DS_Store}"
-  - from: "pandoc/pandoc-linux-amd64.zip"
-    to: "pandoc.zip"
+    filter: "!**/{.DS_Store}"

+ 24 - 3
kernel/util/pandoc.go

@@ -22,6 +22,7 @@ import (
 	"os"
 	"os/exec"
 	"path/filepath"
+	"runtime"
 	"strings"
 
 	"github.com/88250/gulu"
@@ -29,9 +30,11 @@ import (
 	"github.com/siyuan-note/logging"
 )
 
+var ErrPandocNotFound = errors.New("not found executable pandoc")
+
 func ConvertPandoc(dir string, args ...string) (path string, err error) {
 	if "" == PandocBinPath || ContainerStd != Container {
-		err = errors.New("not found executable pandoc")
+		err = ErrPandocNotFound
 		return
 	}
 
@@ -55,6 +58,11 @@ func ConvertPandoc(dir string, args ...string) (path string, err error) {
 }
 
 func Pandoc(from, to, o, content string) (err error) {
+	if "" == PandocBinPath || ContainerStd != Container {
+		err = ErrPandocNotFound
+		return
+	}
+
 	if "" == from || "" == to || "md" == to {
 		if err = gulu.File.WriteFileSafer(o, []byte(content), 0644); nil != err {
 			logging.LogErrorf("write export markdown file [%s] failed: %s", o, err)
@@ -123,9 +131,15 @@ func InitPandoc() {
 	defer eventbus.Publish(EvtConfPandocInitialized)
 
 	if gulu.OS.IsWindows() {
-		PandocBinPath = filepath.Join(pandocDir, "bin", "pandoc.exe")
-	} else if gulu.OS.IsDarwin() || gulu.OS.IsLinux() {
+		if "amd64" == runtime.GOARCH {
+			PandocBinPath = filepath.Join(pandocDir, "bin", "pandoc.exe")
+		}
+	} else if gulu.OS.IsDarwin() {
 		PandocBinPath = filepath.Join(pandocDir, "bin", "pandoc")
+	} else if gulu.OS.IsLinux() {
+		if "amd64" == runtime.GOARCH {
+			PandocBinPath = filepath.Join(pandocDir, "bin", "pandoc")
+		}
 	}
 	pandocVer := getPandocVer(PandocBinPath)
 	if "" != pandocVer {
@@ -143,6 +157,13 @@ func InitPandoc() {
 			pandocZip = filepath.Join(WorkingDir, "pandoc/pandoc-linux-amd64.zip")
 		}
 	}
+
+	if !gulu.File.IsExist(pandocZip) {
+		PandocBinPath = ""
+		logging.LogErrorf("pandoc zip [%s] not found", pandocZip)
+		return
+	}
+
 	if err := gulu.Zip.Unzip(pandocZip, pandocDir); nil != err {
 		logging.LogErrorf("unzip pandoc failed: %s", err)
 		return