|
@@ -25,7 +25,6 @@ import (
|
|
|
"time"
|
|
|
|
|
|
"github.com/88250/gulu"
|
|
|
- "github.com/88250/lute"
|
|
|
"github.com/88250/lute/ast"
|
|
|
"github.com/88250/lute/parse"
|
|
|
"github.com/dustin/go-humanize"
|
|
@@ -39,23 +38,7 @@ 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()
|
|
|
- if ast.NodeDocument == node.Type {
|
|
|
- content = luteEngine.Tree2BlockDOM(tree, luteEngine.RenderOptions)
|
|
|
- } else {
|
|
|
- content = lute.RenderNodeBlockDOM(node, luteEngine.ParseOptions, luteEngine.RenderOptions)
|
|
|
- }
|
|
|
+func SearchFlashcard(deckID string) (blockIDs []string) {
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -365,7 +348,7 @@ func InitFlashcards() {
|
|
|
}
|
|
|
|
|
|
if 1 > len(Decks) {
|
|
|
- deck, createErr := CreateDeck("Default Deck")
|
|
|
+ deck, createErr := createDeck("Default Deck")
|
|
|
if nil == createErr {
|
|
|
Decks[deck.ID] = deck
|
|
|
}
|
|
@@ -402,12 +385,17 @@ func RemoveDeck(deckID string) (err error) {
|
|
|
|
|
|
riffSavePath := getRiffDir()
|
|
|
deckPath := filepath.Join(riffSavePath, deckID+".deck")
|
|
|
- if err = os.Remove(deckPath); nil != err {
|
|
|
- return
|
|
|
+ if gulu.File.IsExist(deckPath) {
|
|
|
+ if err = os.Remove(deckPath); nil != err {
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
cardsPath := filepath.Join(riffSavePath, deckID+".cards")
|
|
|
- if err = os.Remove(cardsPath); nil != err {
|
|
|
- return
|
|
|
+ if gulu.File.IsExist(cardsPath) {
|
|
|
+ if err = os.Remove(cardsPath); nil != err {
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
InitFlashcards()
|
|
@@ -417,7 +405,10 @@ func RemoveDeck(deckID string) (err error) {
|
|
|
func CreateDeck(name string) (deck *riff.Deck, err error) {
|
|
|
deckLock.Lock()
|
|
|
defer deckLock.Unlock()
|
|
|
+ return createDeck(name)
|
|
|
+}
|
|
|
|
|
|
+func createDeck(name string) (deck *riff.Deck, err error) {
|
|
|
if syncingStorages {
|
|
|
err = errors.New(Conf.Language(81))
|
|
|
return
|