From 7a30dea8805805c65c4b281e7af0096f48c0b19e Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 22 Dec 2022 10:24:28 +0800 Subject: [PATCH 1/3] =?UTF-8?q?:art:=20=E5=AF=BC=E5=87=BA=20Markdown=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=97=A5=E6=9C=9F=E5=85=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=8F=98=E6=9B=B4=20Fix=20https://github.com?= =?UTF-8?q?/siyuan-note/siyuan/issues/6905?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/export.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/model/export.go b/kernel/model/export.go index d26e8085b..a359fa7b1 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -812,10 +812,10 @@ func yfm(docIAL map[string]string) string { if "" == created { created = updated } - buf.WriteString("created: ") + buf.WriteString("date: ") buf.WriteString(created) buf.WriteString("\n") - buf.WriteString("updated: ") + buf.WriteString("lastmod: ") buf.WriteString(updated) buf.WriteString("\n") if "" != tags { From fecd965dfb6f188e5ee8df62b613d418fddc7619 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 22 Dec 2022 10:38:15 +0800 Subject: [PATCH 2/3] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E9=97=B4?= =?UTF-8?q?=E9=9A=94=E5=A4=8D=E4=B9=A0=20https://github.com/siyuan-note/si?= =?UTF-8?q?yuan/issues/6710?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/riff.go | 19 +++++++++++++++++++ kernel/api/router.go | 1 + kernel/model/flashcard.go | 27 +++++++++++++++++++++++---- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/kernel/api/riff.go b/kernel/api/riff.go index 27aabef9b..f471d6133 100644 --- a/kernel/api/riff.go +++ b/kernel/api/riff.go @@ -113,6 +113,25 @@ func addRiffCards(c *gin.Context) { } } +func renameRiffDeck(c *gin.Context) { + ret := gulu.Ret.NewResult() + defer c.JSON(http.StatusOK, ret) + + arg, ok := util.JsonArg(c, ret) + if !ok { + return + } + + deckID := arg["deckID"].(string) + name := arg["name"].(string) + err := model.RenameDeck(deckID, name) + if nil != err { + ret.Code = -1 + ret.Msg = err.Error() + return + } +} + func createRiffDeck(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) diff --git a/kernel/api/router.go b/kernel/api/router.go index 3263a27f0..6fc942972 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -300,6 +300,7 @@ func ServeAPI(ginServer *gin.Engine) { ginServer.Handle("POST", "/api/repo/openRepoSnapshotDoc", model.CheckAuth, openRepoSnapshotDoc) ginServer.Handle("POST", "/api/riff/createRiffDeck", model.CheckAuth, createRiffDeck) + ginServer.Handle("POST", "/api/riff/renameRiffDeck", model.CheckAuth, renameRiffDeck) ginServer.Handle("POST", "/api/riff/getRiffDecks", model.CheckAuth, getRiffDecks) ginServer.Handle("POST", "/api/riff/addRiffCards", model.CheckAuth, addRiffCards) ginServer.Handle("POST", "/api/riff/removeRiffCards", model.CheckAuth, removeRiffCards) diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index fa4169e77..d0e1b3b2d 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -22,7 +22,6 @@ import ( "strings" "sync" - "github.com/88250/gulu" "github.com/88250/lute/ast" "github.com/siyuan-note/logging" "github.com/siyuan-note/riff" @@ -106,7 +105,8 @@ func AddFlashcards(deckID string, blockIDs []string) (err error) { func InitFlashcards() { riffSavePath := getRiffDir() - if !gulu.File.IsDir(riffSavePath) { + if err := os.MkdirAll(riffSavePath, 0755); nil != err { + logging.LogErrorf("create riff dir [%s] failed: %s", riffSavePath, err) return } @@ -125,11 +125,30 @@ func InitFlashcards() { continue } - deckLock.Lock() Decks[deckID] = deck - deckLock.Unlock() } } + + if 1 > len(Decks) { + deck, createErr := CreateDeck("Default Deck") + if nil == createErr { + Decks[deck.ID] = deck + } + } +} + +func RenameDeck(deckID string, name string) (err error) { + deckLock.Lock() + deck := Decks[deckID] + deckLock.Unlock() + + deck.Name = name + err = deck.Save() + if nil != err { + logging.LogErrorf("save deck [%s] failed: %s", deckID, err) + return + } + return } func CreateDeck(name string) (deck *riff.Deck, err error) { From c5b1279c82c077dd53a26dd94eb068bbabb42df1 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 22 Dec 2022 10:59:33 +0800 Subject: [PATCH 3/3] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E9=97=B4?= =?UTF-8?q?=E9=9A=94=E5=A4=8D=E4=B9=A0=20https://github.com/siyuan-note/si?= =?UTF-8?q?yuan/issues/6710?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/riff.go | 1 - kernel/model/flashcard.go | 36 +++++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/kernel/api/riff.go b/kernel/api/riff.go index f471d6133..af81ab68f 100644 --- a/kernel/api/riff.go +++ b/kernel/api/riff.go @@ -56,7 +56,6 @@ func getRiffDueCards(c *gin.Context) { } deckID := arg["deckID"].(string) - cards, err := model.GetDueFlashcards(deckID) if nil != err { ret.Code = -1 diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index d0e1b3b2d..aac181e8d 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -45,12 +45,11 @@ func ReviewFlashcard(deckID string, blockID string, rating riff.Rating) (err err return } -type Flashcard struct { - ID string - BlockID string -} +func GetDueFlashcards(deckID string) (ret []string, err error) { + if "" == deckID { + return getAllDueFlashcards() + } -func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) { deckLock.Lock() deck := Decks[deckID] deckLock.Unlock() @@ -62,10 +61,29 @@ func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) { if nil != getErr { continue } - ret = append(ret, &Flashcard{ - ID: card.ID(), - BlockID: blockID, - }) + ret = append(ret, blockID) + } + return +} + +func getAllDueFlashcards() (ret []string, err error) { + blockIDs := map[string]bool{} + for _, deck := range Decks { + cards := deck.Dues() + for _, card := range cards { + blockID := card.BlockID() + _, getErr := GetBlock(blockID) + if nil != getErr { + continue + } + + if blockIDs[blockID] { + continue + } + + ret = append(ret, blockID) + blockIDs[blockID] = true + } } return }