♻️ Extract method util.GetTreeID

This commit is contained in:
Daniel 2024-11-29 08:41:43 +08:00
parent c295a496d7
commit 6f7e106be4
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
11 changed files with 26 additions and 27 deletions

View file

@ -310,7 +310,7 @@ func ListDocTree(boxID, listPath string, sortMode int, flashcard, showHidden boo
}
if flashcard {
rootID := strings.TrimSuffix(filepath.Base(parentDocPath), ".sy")
rootID := util.GetTreeID(parentDocPath)
newFlashcardCount, dueFlashcardCount, flashcardCount := countTreeFlashcard(rootID, deck, deckBlockIDs)
if 0 < flashcardCount {
doc.NewFlashcardCount = newFlashcardCount
@ -339,7 +339,7 @@ func ListDocTree(boxID, listPath string, sortMode int, flashcard, showHidden boo
doc := box.docFromFileInfo(file, ial)
if flashcard {
rootID := strings.TrimSuffix(filepath.Base(file.path), ".sy")
rootID := util.GetTreeID(file.path)
newFlashcardCount, dueFlashcardCount, flashcardCount := countTreeFlashcard(rootID, deck, deckBlockIDs)
if 0 < flashcardCount {
doc.NewFlashcardCount = newFlashcardCount
@ -1833,7 +1833,7 @@ func createDoc(boxID, p, title, dom string) (tree *parse.Tree, err error) {
}
baseName := strings.TrimSpace(path.Base(p))
if "" == strings.TrimSuffix(baseName, ".sy") {
if "" == util.GetTreeID(baseName) {
err = errors.New(Conf.Language(16))
return
}
@ -1849,7 +1849,7 @@ func createDoc(boxID, p, title, dom string) (tree *parse.Tree, err error) {
return
}
id := strings.TrimSuffix(path.Base(p), ".sy")
id := util.GetTreeID(p)
var hPath string
folder := path.Dir(p)
if "/" != folder {
@ -2006,7 +2006,7 @@ func ChangeFileTreeSort(boxID string, paths []string) {
sortIDs := map[string]int{}
max := 0
for i, p := range paths {
id := strings.TrimSuffix(path.Base(p), ".sy")
id := util.GetTreeID(p)
sortIDs[id] = i + 1
if i == len(paths)-1 {
max = i + 2