Browse Source

:sparkles: 分享文档到链滴 https://github.com/siyuan-note/siyuan/issues/2004

Liang Ding 2 years ago
parent
commit
068c03f9d7
2 changed files with 23 additions and 15 deletions
  1. 1 1
      kernel/api/lute.go
  2. 22 14
      kernel/model/export.go

+ 1 - 1
kernel/api/lute.go

@@ -42,7 +42,7 @@ func copyStdMarkdown(c *gin.Context) {
 	}
 	}
 
 
 	id := arg["id"].(string)
 	id := arg["id"].(string)
-	ret.Data = model.CopyStdMarkdown(id)
+	ret.Data = model.ExportStdMarkdown(id)
 }
 }
 
 
 func html2BlockDOM(c *gin.Context) {
 func html2BlockDOM(c *gin.Context) {

+ 22 - 14
kernel/model/export.go

@@ -93,7 +93,7 @@ func Export2Liandi(id string) (err error) {
 
 
 	title := path.Base(tree.HPath)
 	title := path.Base(tree.HPath)
 	tags := tree.Root.IALAttr("tags")
 	tags := tree.Root.IALAttr("tags")
-	content := exportMarkdownContent0(tree)
+	content := exportMarkdownContent0(tree, "https://b3logfile.com/siyuan/")
 	var result = gulu.Ret.NewResult()
 	var result = gulu.Ret.NewResult()
 	request := httpclient.NewCloudRequest30s()
 	request := httpclient.NewCloudRequest30s()
 	request = request.
 	request = request.
@@ -123,7 +123,7 @@ func Export2Liandi(id string) (err error) {
 	if 0 != result.Code {
 	if 0 != result.Code {
 		msg := fmt.Sprintf("send article to liandi failed [code=%d, msg=%s]", result.Code, result.Msg)
 		msg := fmt.Sprintf("send article to liandi failed [code=%d, msg=%s]", result.Code, result.Msg)
 		logging.LogErrorf(msg)
 		logging.LogErrorf(msg)
-		return errors.New(msg)
+		return errors.New(result.Msg)
 	}
 	}
 
 
 	if !foundArticle {
 	if !foundArticle {
@@ -694,17 +694,18 @@ func AddPDFOutline(id, p string, merge bool) (err error) {
 	return
 	return
 }
 }
 
 
-func CopyStdMarkdown(id string) string {
-	tree, _ := loadTreeByBlockID(id)
-	tree = exportTree(tree, false, false, false)
-	luteEngine := NewLute()
-	luteEngine.SetFootnotes(true)
-	luteEngine.SetKramdownIAL(false)
+func ExportStdMarkdown(id string) string {
+	tree, err := loadTreeByBlockID(id)
+	if nil != err {
+		logging.LogErrorf("load tree by block id [%s] failed: %s", id, err)
+		return ""
+	}
+
+	cloudAssetsBase := ""
 	if IsSubscriber() {
 	if IsSubscriber() {
-		// 订阅用户使用云端图床服务
-		luteEngine.RenderOptions.LinkBase = "https://assets.b3logfile.com/siyuan/" + Conf.User.UserId + "/"
+		cloudAssetsBase = "https://assets.b3logfile.com/siyuan/"
 	}
 	}
-	return treenode.ExportNodeStdMd(tree.Root, luteEngine)
+	return exportMarkdownContent0(tree, cloudAssetsBase)
 }
 }
 
 
 func ExportMarkdown(id string) (name, zipPath string) {
 func ExportMarkdown(id string) (name, zipPath string) {
@@ -1132,17 +1133,24 @@ func ExportMarkdownContent(id string) (hPath, exportedMd string) {
 }
 }
 
 
 func exportMarkdownContent(id string) (hPath, exportedMd string) {
 func exportMarkdownContent(id string) (hPath, exportedMd string) {
-	tree, _ := loadTreeByBlockID(id)
+	tree, err := loadTreeByBlockID(id)
+	if nil != err {
+		logging.LogErrorf("load tree by block id [%s] failed: %s", id, err)
+		return
+	}
 	hPath = tree.HPath
 	hPath = tree.HPath
-	exportedMd = exportMarkdownContent0(tree)
+	exportedMd = exportMarkdownContent0(tree, "")
 	return
 	return
 }
 }
 
 
-func exportMarkdownContent0(tree *parse.Tree) (ret string) {
+func exportMarkdownContent0(tree *parse.Tree, cloudAssetsBase string) (ret string) {
 	tree = exportTree(tree, false, true, false)
 	tree = exportTree(tree, false, true, false)
 	luteEngine := NewLute()
 	luteEngine := NewLute()
 	luteEngine.SetFootnotes(true)
 	luteEngine.SetFootnotes(true)
 	luteEngine.SetKramdownIAL(false)
 	luteEngine.SetKramdownIAL(false)
+	if "" != cloudAssetsBase {
+		luteEngine.RenderOptions.LinkBase = cloudAssetsBase + Conf.User.UserId + "/"
+	}
 	renderer := render.NewProtyleExportMdRenderer(tree, luteEngine.RenderOptions)
 	renderer := render.NewProtyleExportMdRenderer(tree, luteEngine.RenderOptions)
 	ret = gulu.Str.FromBytes(renderer.Render())
 	ret = gulu.Str.FromBytes(renderer.Render())
 	return
 	return