فهرست منبع

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

Vanessa 2 سال پیش
والد
کامیت
5dab4ef6f4
5فایلهای تغییر یافته به همراه58 افزوده شده و 6 حذف شده
  1. 22 0
      kernel/api/riff.go
  2. 1 0
      kernel/api/router.go
  3. 2 2
      kernel/go.mod
  4. 4 4
      kernel/go.sum
  5. 29 0
      kernel/model/flashcard.go

+ 22 - 0
kernel/api/riff.go

@@ -26,6 +26,28 @@ import (
 	"github.com/siyuan-note/siyuan/kernel/util"
 )
 
+func renderRiffCard(c *gin.Context) {
+	ret := gulu.Ret.NewResult()
+	defer c.JSON(http.StatusOK, ret)
+
+	arg, ok := util.JsonArg(c, ret)
+	if !ok {
+		return
+	}
+
+	blockID := arg["blockID"].(string)
+	content, err := model.RenderFlashcard(blockID)
+	if nil != err {
+		ret.Code = -1
+		ret.Msg = err.Error()
+		return
+	}
+
+	ret.Data = map[string]interface{}{
+		"content": content,
+	}
+}
+
 func reviewRiffCard(c *gin.Context) {
 	ret := gulu.Ret.NewResult()
 	defer c.JSON(http.StatusOK, ret)

+ 1 - 0
kernel/api/router.go

@@ -305,6 +305,7 @@ func ServeAPI(ginServer *gin.Engine) {
 	ginServer.Handle("POST", "/api/riff/addRiffCards", model.CheckAuth, addRiffCards)
 	ginServer.Handle("POST", "/api/riff/removeRiffCards", model.CheckAuth, removeRiffCards)
 	ginServer.Handle("POST", "/api/riff/getRiffDueCards", model.CheckAuth, getRiffDueCards)
+	ginServer.Handle("POST", "/api/riff/renderRiffCard", model.CheckAuth, renderRiffCard)
 	ginServer.Handle("POST", "/api/riff/reviewRiffCard", model.CheckAuth, reviewRiffCard)
 
 	ginServer.Handle("POST", "/api/notification/pushMsg", model.CheckAuth, pushMsg)

+ 2 - 2
kernel/go.mod

@@ -39,7 +39,7 @@ require (
 	github.com/patrickmn/go-cache v2.1.0+incompatible
 	github.com/radovskyb/watcher v1.0.7
 	github.com/shirou/gopsutil/v3 v3.22.11
-	github.com/siyuan-note/dejavu v0.0.0-20221221065751-91ea22509756
+	github.com/siyuan-note/dejavu v0.0.0-20221222064045-9ad75d85c281
 	github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75
 	github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da
 	github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e
@@ -62,7 +62,7 @@ require (
 	github.com/alecthomas/chroma v0.10.0 // indirect
 	github.com/andybalholm/cascadia v1.3.1 // indirect
 	github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect
-	github.com/aws/aws-sdk-go v1.44.164 // indirect
+	github.com/aws/aws-sdk-go v1.44.165 // indirect
 	github.com/cespare/xxhash/v2 v2.2.0 // indirect
 	github.com/dlclark/regexp2 v1.7.0 // indirect
 	github.com/dsnet/compress v0.0.1 // indirect

+ 4 - 4
kernel/go.sum

@@ -46,8 +46,8 @@ github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhP
 github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw=
 github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef h1:2JGTg6JapxP9/R33ZaagQtAM4EkkSYnIAlOG5EI8gkM=
 github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef/go.mod h1:JS7hed4L1fj0hXcyEejnW57/7LCetXggd+vwrRnYeII=
-github.com/aws/aws-sdk-go v1.44.164 h1:qDj0RutF2Ut0HZYyUJxFdReLxpYrjupsu2JmDIgCvX8=
-github.com/aws/aws-sdk-go v1.44.164/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
+github.com/aws/aws-sdk-go v1.44.165 h1:yaeKEU28EiSCp1T5XXinVA/qx9JFGbVZGUmj5COAMXI=
+github.com/aws/aws-sdk-go v1.44.165/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
 github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
 github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
 github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
@@ -373,8 +373,8 @@ github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1l
 github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
 github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4=
 github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw=
-github.com/siyuan-note/dejavu v0.0.0-20221221065751-91ea22509756 h1:lp8ihGlC8Mlqn8zI8CeFzWzoi90EaFTWBuCFUwGC5fg=
-github.com/siyuan-note/dejavu v0.0.0-20221221065751-91ea22509756/go.mod h1:bemsV89S70xPIoY6CX9SkL3IX6YkCwS8nK09KTKg/S4=
+github.com/siyuan-note/dejavu v0.0.0-20221222064045-9ad75d85c281 h1:BgUWOAGXlYCKWzSlUXrPssgaViQihGL92ty2GxQacik=
+github.com/siyuan-note/dejavu v0.0.0-20221222064045-9ad75d85c281/go.mod h1:bemsV89S70xPIoY6CX9SkL3IX6YkCwS8nK09KTKg/S4=
 github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE=
 github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
 github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da h1:/jNhl7LC+9BhkWvNxuJDdsNfA/2wvfuj9mqWx4CbV90=

+ 29 - 0
kernel/model/flashcard.go

@@ -17,6 +17,8 @@
 package model
 
 import (
+	"github.com/88250/lute"
+	"github.com/siyuan-note/siyuan/kernel/treenode"
 	"os"
 	"path/filepath"
 	"strings"
@@ -31,6 +33,27 @@ import (
 var Decks = map[string]*riff.Deck{}
 var deckLock = sync.Mutex{}
 
+func RenderFlashcard(blockID string) (content string, err error) {
+	tree, err := loadTreeByBlockID(blockID)
+	if nil != err {
+		return
+	}
+
+	node := treenode.GetNodeInTree(tree, blockID)
+	if nil == node {
+		return
+	}
+
+	luteEngine := NewLute()
+	luteEngine.RenderOptions.ProtyleContenteditable = false
+	if ast.NodeDocument == node.Type {
+		content = luteEngine.Tree2BlockDOM(tree, luteEngine.RenderOptions)
+	} else {
+		content = lute.RenderNodeBlockDOM(node, luteEngine.ParseOptions, luteEngine.RenderOptions)
+	}
+	return
+}
+
 func ReviewFlashcard(deckID string, blockID string, rating riff.Rating) (err error) {
 	deckLock.Lock()
 	deck := Decks[deckID]
@@ -63,6 +86,9 @@ func GetDueFlashcards(deckID string) (ret []string, err error) {
 		}
 		ret = append(ret, blockID)
 	}
+	if 1 > len(ret) {
+		ret = []string{}
+	}
 	return
 }
 
@@ -85,6 +111,9 @@ func getAllDueFlashcards() (ret []string, err error) {
 			blockIDs[blockID] = true
 		}
 	}
+	if 1 > len(ret) {
+		ret = []string{}
+	}
 	return
 }