소스 검색

:art: Cloud inbox support preview audio and video https://github.com/siyuan-note/siyuan/issues/9780

Daniel 1 년 전
부모
커밋
6ccf76e6cd
3개의 변경된 파일32개의 추가작업 그리고 3개의 파일을 삭제
  1. 3 3
      app/src/layout/dock/Inbox.ts
  2. 1 0
      app/src/types/index.d.ts
  3. 28 0
      kernel/model/cloud_service.go

+ 3 - 3
app/src/layout/dock/Inbox.ts

@@ -199,7 +199,7 @@ export class Inbox extends Model {
     ${linkHTML}
 </div>
 <div class="b3-typography b3-typography--default" style="padding: 0 8px 8px">
-${(Lute.New()).MarkdownStr("", data.shorthandContent)}
+${data.shorthandContent}
 </div>`;
         /// #else
         if (data.shorthandURL) {
@@ -214,7 +214,7 @@ ${(Lute.New()).MarkdownStr("", data.shorthandContent)}
     ${linkHTML}
 </div>
 <div class="b3-typography b3-typography--default" style="padding: 0 8px 8px;user-select: text">
-${(Lute.New()).MarkdownStr("", data.shorthandContent)}
+${data.shorthandContent}
 </div>`;
         /// #endif
     }
@@ -332,7 +332,7 @@ ${(Lute.New()).MarkdownStr("", data.shorthandContent)}
                         notebook: toNotebook[0],
                         path: pathPosix().join(getDisplayName(toPath[0], false, true), Lute.NewNodeID() + ".sy"),
                         title: replaceFileName(response.data.shorthandTitle),
-                        md: response.data.shorthandContent,
+                        md: response.data.shorthandMd,
                     }, (docResponse) => {
                         this.remove(item);
                         fetchPost("/api/format/netAssets2LocalAssets", {id: docResponse.data.id});

+ 1 - 0
app/src/types/index.d.ts

@@ -262,6 +262,7 @@ interface ISnippet {
 interface IInbox {
     oId: string
     shorthandContent: string
+    shorthandMd: string
     shorthandDesc: string
     shorthandFrom: number
     shorthandTitle: string

+ 28 - 0
kernel/model/cloud_service.go

@@ -23,11 +23,13 @@ import (
 	"net/http"
 	"os"
 	"path/filepath"
+	"regexp"
 	"strconv"
 	"strings"
 	"time"
 
 	"github.com/88250/gulu"
+	"github.com/88250/lute/parse"
 	"github.com/siyuan-note/httpclient"
 	"github.com/siyuan-note/logging"
 	"github.com/siyuan-note/siyuan/kernel/conf"
@@ -456,6 +458,15 @@ func GetCloudShorthand(id string) (ret map[string]interface{}, err error) {
 	t, _ := strconv.ParseInt(id, 10, 64)
 	hCreated := util.Millisecond2Time(t)
 	ret["hCreated"] = hCreated.Format("2006-01-02 15:04")
+
+	md := ret["shorthandContent"].(string)
+	ret["shorthandMd"] = md
+
+	luteEngine := NewLute()
+	luteEngine.SetFootnotes(true)
+	tree := parse.Parse("", []byte(md), luteEngine.ParseOptions)
+	content := luteEngine.ProtylePreview(tree, luteEngine.RenderOptions)
+	ret["shorthandContent"] = content
 	return
 }
 
@@ -483,6 +494,10 @@ func GetCloudShorthands(page int) (result map[string]interface{}, err error) {
 		err = errors.New(result["msg"].(string))
 		return
 	}
+
+	luteEngine := NewLute()
+	audioRegexp := regexp.MustCompile("<audio.*>.*</audio>")
+	videoRegexp := regexp.MustCompile("<video.*>.*</video>")
 	shorthands := result["data"].(map[string]interface{})["shorthands"].([]interface{})
 	for _, item := range shorthands {
 		shorthand := item.(map[string]interface{})
@@ -490,6 +505,19 @@ func GetCloudShorthands(page int) (result map[string]interface{}, err error) {
 		t, _ := strconv.ParseInt(id, 10, 64)
 		hCreated := util.Millisecond2Time(t)
 		shorthand["hCreated"] = hCreated.Format("2006-01-02 15:04")
+
+		desc := shorthand["shorthandDesc"].(string)
+		desc = audioRegexp.ReplaceAllString(desc, "语音、")
+		desc = videoRegexp.ReplaceAllString(desc, "视频、")
+		desc = strings.TrimSuffix(desc, "、")
+		desc = strings.ReplaceAll(desc, "\n\n", "")
+		shorthand["shorthandDesc"] = desc
+
+		md := shorthand["shorthandContent"].(string)
+		shorthand["shorthandMd"] = md
+		tree := parse.Parse("", []byte(md), luteEngine.ParseOptions)
+		content := luteEngine.ProtylePreview(tree, luteEngine.RenderOptions)
+		shorthand["shorthandContent"] = content
 	}
 	return
 }