mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
🎨 Export related flashcard data when exporting .sy.zip https://github.com/siyuan-note/siyuan/issues/9372
This commit is contained in:
parent
2ca7253d1f
commit
a8806968d0
3 changed files with 72 additions and 2 deletions
|
|
@ -46,6 +46,7 @@ import (
|
||||||
"github.com/siyuan-note/filelock"
|
"github.com/siyuan-note/filelock"
|
||||||
"github.com/siyuan-note/httpclient"
|
"github.com/siyuan-note/httpclient"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
|
"github.com/siyuan-note/riff"
|
||||||
"github.com/siyuan-note/siyuan/kernel/av"
|
"github.com/siyuan-note/siyuan/kernel/av"
|
||||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||||
|
|
@ -1382,6 +1383,27 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 导出闪卡 Export related flashcard data when exporting .sy.zip https://github.com/siyuan-note/siyuan/issues/9372
|
||||||
|
exportStorageRiffDir := filepath.Join(exportFolder, "storage", "riff")
|
||||||
|
deckID := ast.NewNodeID()
|
||||||
|
deck, loadErr := riff.LoadDeck(exportStorageRiffDir, deckID, Conf.Flashcard.RequestRetention, Conf.Flashcard.MaximumInterval, Conf.Flashcard.Weights)
|
||||||
|
for _, tree := range trees {
|
||||||
|
cards := getTreeFlashcards(tree.ID)
|
||||||
|
if nil != loadErr {
|
||||||
|
logging.LogErrorf("load deck [%s] failed: %s", name, loadErr)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, card := range cards {
|
||||||
|
deck.AddCard(card.ID(), card.BlockID())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if 0 < deck.CountCards() {
|
||||||
|
if saveErr := deck.Save(); nil != saveErr {
|
||||||
|
logging.LogErrorf("save deck [%s] failed: %s", name, saveErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 导出自定义排序
|
// 导出自定义排序
|
||||||
sortPath := filepath.Join(util.DataDir, box.ID, ".siyuan", "sort.json")
|
sortPath := filepath.Join(util.DataDir, box.ID, ".siyuan", "sort.json")
|
||||||
fullSortIDs := map[string]int{}
|
fullSortIDs := map[string]int{}
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
func GetTreeFlashcards(rootID string, page int) (blocks []*Block, total, pageCount int) {
|
||||||
blocks = []*Block{}
|
blocks = []*Block{}
|
||||||
|
cards := getTreeSubTreeFlashcards(rootID)
|
||||||
|
blocks, total, pageCount = getCardsBlocks(cards, page)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTreeSubTreeFlashcards(rootID string) (ret []riff.Card) {
|
||||||
deck := Decks[builtinDeckID]
|
deck := Decks[builtinDeckID]
|
||||||
if nil == deck {
|
if nil == deck {
|
||||||
return
|
return
|
||||||
|
|
@ -162,9 +168,26 @@ func GetTreeFlashcards(rootID string, page int) (blocks []*Block, total, pageCou
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allBlockIDs = gulu.Str.RemoveDuplicatedElem(allBlockIDs)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -420,6 +443,16 @@ func getTreeSubTreeChildBlocks(rootID string) (treeBlockIDsMap map[string]bool,
|
||||||
return
|
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) {
|
func getBoxBlocks(boxID string) (blockIDsMap map[string]bool, blockIDs []string) {
|
||||||
blockIDsMap = map[string]bool{}
|
blockIDsMap = map[string]bool{}
|
||||||
bts := treenode.GetBlockTreesByBoxID(boxID)
|
bts := treenode.GetBlockTreesByBoxID(boxID)
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,21 @@ func GetBlockTreesByPathPrefix(pathPrefix string) (ret []*BlockTree) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetBlockTreesByRootID(rootID string) (ret []*BlockTree) {
|
||||||
|
blockTrees.Range(func(key, value interface{}) bool {
|
||||||
|
slice := value.(*btSlice)
|
||||||
|
slice.m.Lock()
|
||||||
|
for _, b := range slice.data {
|
||||||
|
if b.RootID == rootID {
|
||||||
|
ret = append(ret, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
slice.m.Unlock()
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func RemoveBlockTreesByPathPrefix(pathPrefix string) {
|
func RemoveBlockTreesByPathPrefix(pathPrefix string) {
|
||||||
var ids []string
|
var ids []string
|
||||||
blockTrees.Range(func(key, value interface{}) bool {
|
blockTrees.Range(func(key, value interface{}) bool {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue