🎨 Export related flashcard data when exporting .sy.zip https://github.com/siyuan-note/siyuan/issues/9372

This commit is contained in:
Daniel 2023-10-08 16:35:06 +08:00
parent 2ca7253d1f
commit a8806968d0
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 72 additions and 2 deletions

View file

@ -148,6 +148,12 @@ func GetNotebookFlashcards(boxID string, page int) (blocks []*Block, total, page
func GetTreeFlashcards(rootID string, page int) (blocks []*Block, total, pageCount int) {
blocks = []*Block{}
cards := getTreeSubTreeFlashcards(rootID)
blocks, total, pageCount = getCardsBlocks(cards, page)
return
}
func getTreeSubTreeFlashcards(rootID string) (ret []riff.Card) {
deck := Decks[builtinDeckID]
if nil == deck {
return
@ -162,9 +168,26 @@ func GetTreeFlashcards(rootID string, page int) (blocks []*Block, total, pageCou
}
}
allBlockIDs = gulu.Str.RemoveDuplicatedElem(allBlockIDs)
cards := deck.GetCardsByBlockIDs(allBlockIDs)
ret = deck.GetCardsByBlockIDs(allBlockIDs)
return
}
blocks, total, pageCount = getCardsBlocks(cards, page)
func getTreeFlashcards(rootID string) (ret []riff.Card) {
deck := Decks[builtinDeckID]
if nil == deck {
return
}
var allBlockIDs []string
deckBlockIDs := deck.GetBlockIDs()
treeBlockIDsMap, _ := getTreeBlocks(rootID)
for _, blockID := range deckBlockIDs {
if treeBlockIDsMap[blockID] {
allBlockIDs = append(allBlockIDs, blockID)
}
}
allBlockIDs = gulu.Str.RemoveDuplicatedElem(allBlockIDs)
ret = deck.GetCardsByBlockIDs(allBlockIDs)
return
}
@ -420,6 +443,16 @@ func getTreeSubTreeChildBlocks(rootID string) (treeBlockIDsMap map[string]bool,
return
}
func getTreeBlocks(rootID string) (treeBlockIDsMap map[string]bool, treeBlockIDs []string) {
treeBlockIDsMap = map[string]bool{}
bts := treenode.GetBlockTreesByRootID(rootID)
for _, bt := range bts {
treeBlockIDsMap[bt.ID] = true
treeBlockIDs = append(treeBlockIDs, bt.ID)
}
return
}
func getBoxBlocks(boxID string) (blockIDsMap map[string]bool, blockIDs []string) {
blockIDsMap = map[string]bool{}
bts := treenode.GetBlockTreesByBoxID(boxID)