Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
1942c3be0d
11 changed files with 43 additions and 36 deletions
|
@ -19,8 +19,6 @@ package api
|
|||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute"
|
||||
|
@ -113,7 +111,7 @@ func appendDailyNoteBlock(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
parentID := strings.TrimSuffix(path.Base(p), ".sy")
|
||||
parentID := util.GetTreeID(p)
|
||||
transactions := []*model.Transaction{
|
||||
{
|
||||
DoOperations: []*model.Operation{
|
||||
|
@ -166,7 +164,7 @@ func prependDailyNoteBlock(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
parentID := strings.TrimSuffix(path.Base(p), ".sy")
|
||||
parentID := util.GetTreeID(p)
|
||||
transactions := []*model.Transaction{
|
||||
{
|
||||
DoOperations: []*model.Operation{
|
||||
|
|
|
@ -708,7 +708,7 @@ func getBoxesByPaths(paths []string) (ret map[string]*Box) {
|
|||
ret = map[string]*Box{}
|
||||
var ids []string
|
||||
for _, p := range paths {
|
||||
ids = append(ids, strings.TrimSuffix(path.Base(p), ".sy"))
|
||||
ids = append(ids, util.GetTreeID(p))
|
||||
}
|
||||
|
||||
bts := treenode.GetBlockTrees(ids)
|
||||
|
|
|
@ -404,7 +404,7 @@ func ExportSY(id string) (name, zipPath string) {
|
|||
docPaths = append(docPaths, docFile.path)
|
||||
}
|
||||
zipPath = exportSYZip(boxID, path.Dir(rootPath), baseFolderName, docPaths)
|
||||
name = strings.TrimSuffix(filepath.Base(block.Path), ".sy")
|
||||
name = util.GetTreeID(block.Path)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1409,7 +1409,7 @@ func BatchExportPandocConvertZip(ids []string, pandocTo, ext string) (name, zipP
|
|||
docPaths = util.FilterSelfChildDocs(docPaths)
|
||||
|
||||
zipPath = exportPandocConvertZip(false, box.ID, baseFolderName, docPaths, "gfm+footnotes+hard_line_breaks", pandocTo, ext)
|
||||
name = strings.TrimSuffix(filepath.Base(block.Path), ".sy")
|
||||
name = util.GetTreeID(block.Path)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1433,7 +1433,7 @@ func ExportPandocConvertZip(id, pandocTo, ext string) (name, zipPath string) {
|
|||
}
|
||||
|
||||
zipPath = exportPandocConvertZip(false, boxID, baseFolderName, docPaths, "gfm+footnotes+hard_line_breaks", pandocTo, ext)
|
||||
name = strings.TrimSuffix(filepath.Base(block.Path), ".sy")
|
||||
name = util.GetTreeID(block.Path)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -2627,7 +2627,7 @@ func resolveFootnotesDefs(refFootnotes *[]*refAsFootnotes, currentTree *parse.Tr
|
|||
continue
|
||||
}
|
||||
defNode := treenode.GetNodeInTree(t, foot.defID)
|
||||
docID := strings.TrimSuffix(path.Base(defNode.Path), ".sy")
|
||||
docID := util.GetTreeID(defNode.Path)
|
||||
var nodes []*ast.Node
|
||||
if ast.NodeHeading == defNode.Type {
|
||||
nodes = append(nodes, defNode)
|
||||
|
@ -2721,7 +2721,7 @@ func resolveFootnotesDefs(refFootnotes *[]*refAsFootnotes, currentTree *parse.Tr
|
|||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
docID := strings.TrimSuffix(path.Base(n.Path), ".sy")
|
||||
docID := util.GetTreeID(n.Path)
|
||||
if currentTree.ID == docID {
|
||||
// 同文档块引转脚注缩略定义 https://github.com/siyuan-note/siyuan/issues/3299
|
||||
if text := sql.GetRefText(n.ID); 64 < utf8.RuneCountInString(text) {
|
||||
|
|
|
@ -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
|
||||
|
@ -2175,7 +2175,7 @@ func (box *Box) addMinSort(parentPath, id string) {
|
|||
}
|
||||
}
|
||||
|
||||
func (box *Box) addSort(previousID, id string) {
|
||||
func (box *Box) addSort(previousPath, id string) {
|
||||
confDir := filepath.Join(util.DataDir, box.ID, ".siyuan")
|
||||
if err := os.MkdirAll(confDir, 0755); err != nil {
|
||||
logging.LogErrorf("create conf dir failed: %s", err)
|
||||
|
@ -2196,17 +2196,25 @@ func (box *Box) addSort(previousID, id string) {
|
|||
}
|
||||
}
|
||||
|
||||
sortVal := 0
|
||||
previousSortVal, ok := fullSortIDs[previousID]
|
||||
if !ok {
|
||||
sortVal++
|
||||
} else {
|
||||
sortVal = previousSortVal + 1
|
||||
parentPath := path.Dir(previousPath)
|
||||
docs, _, err := ListDocTree(box.ID, parentPath, util.SortModeUnassigned, false, false, Conf.FileTree.MaxListCount)
|
||||
if err != nil {
|
||||
logging.LogErrorf("list doc tree failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
fullSortIDs[id] = sortVal
|
||||
previousID := util.GetTreeID(previousPath)
|
||||
sortVal := 0
|
||||
for _, doc := range docs {
|
||||
fullSortIDs[doc.ID] = sortVal
|
||||
if doc.ID == previousID {
|
||||
sortVal++
|
||||
fullSortIDs[id] = sortVal
|
||||
}
|
||||
sortVal++
|
||||
}
|
||||
|
||||
data, err := gulu.JSON.MarshalJSON(fullSortIDs)
|
||||
data, err = gulu.JSON.MarshalJSON(fullSortIDs)
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal sort conf failed: %s", err)
|
||||
return
|
||||
|
|
|
@ -394,7 +394,7 @@ func Heading2Doc(srcHeadingID, targetBoxID, targetPath, previousPath string) (sr
|
|||
newTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
|
||||
newTree.Root.Spec = "1"
|
||||
if "" != previousPath {
|
||||
box.addSort(strings.TrimSuffix(path.Base(previousPath), ".sy"), newTree.ID)
|
||||
box.addSort(previousPath, newTree.ID)
|
||||
} else {
|
||||
box.addMinSort(path.Dir(newTargetPath), newTree.ID)
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"io/fs"
|
||||
"math"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
@ -229,9 +230,7 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
|
|||
|
||||
srcPath := historyPath
|
||||
var destPath, parentHPath string
|
||||
baseName := filepath.Base(historyPath)
|
||||
id := strings.TrimSuffix(baseName, ".sy")
|
||||
|
||||
id := util.GetTreeID(historyPath)
|
||||
workingDoc := treenode.GetBlockTree(id)
|
||||
if nil != workingDoc {
|
||||
if err = filelock.Remove(filepath.Join(util.DataDir, boxID, workingDoc.Path)); err != nil {
|
||||
|
@ -334,7 +333,7 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
|
|||
|
||||
func getRollbackDockPath(boxID, historyPath string) (destPath, parentHPath string, err error) {
|
||||
baseName := filepath.Base(historyPath)
|
||||
parentID := strings.TrimSuffix(filepath.Base(filepath.Dir(historyPath)), ".sy")
|
||||
parentID := path.Base(filepath.Dir(historyPath))
|
||||
parentWorkingDoc := treenode.GetBlockTree(parentID)
|
||||
if nil != parentWorkingDoc {
|
||||
// 父路径如果是文档,则恢复到父路径下
|
||||
|
|
|
@ -758,7 +758,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
targetPaths[curRelPath] = targetPath
|
||||
} else {
|
||||
targetPath = targetPaths[curRelPath]
|
||||
id = strings.TrimSuffix(path.Base(targetPath), ".sy")
|
||||
id = util.GetTreeID(targetPath)
|
||||
}
|
||||
|
||||
if d.IsDir() {
|
||||
|
|
|
@ -128,7 +128,7 @@ func ListItem2Doc(srcListItemID, targetBoxID, targetPath, previousPath string) (
|
|||
newTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
|
||||
newTree.Root.Spec = "1"
|
||||
if "" != previousPath {
|
||||
box.addSort(strings.TrimSuffix(path.Base(previousPath), ".sy"), newTree.ID)
|
||||
box.addSort(previousPath, newTree.ID)
|
||||
} else {
|
||||
box.addMinSort(path.Dir(newTargetPath), newTree.ID)
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
@ -293,7 +292,7 @@ func removeIndexes(removeFilePaths []string) (removeRootIDs []string) {
|
|||
continue
|
||||
}
|
||||
|
||||
id := strings.TrimSuffix(filepath.Base(removeFile), ".sy")
|
||||
id := util.GetTreeID(removeFile)
|
||||
removeRootIDs = append(removeRootIDs, id)
|
||||
block := treenode.GetBlockTree(id)
|
||||
if nil != block {
|
||||
|
@ -338,7 +337,7 @@ func upsertIndexes(upsertFilePaths []string) (upsertRootIDs []string) {
|
|||
|
||||
box := upsertFile[:idx]
|
||||
p := strings.TrimPrefix(upsertFile, box)
|
||||
msg := fmt.Sprintf(Conf.Language(40), strings.TrimSuffix(path.Base(p), ".sy"))
|
||||
msg := fmt.Sprintf(Conf.Language(40), util.GetTreeID(p))
|
||||
util.IncBootProgress(bootProgressPart, msg)
|
||||
util.PushStatusBar(msg)
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"crypto/sha256"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
@ -61,7 +60,7 @@ func TreeRoot(node *ast.Node) *ast.Node {
|
|||
}
|
||||
|
||||
func NewTree(boxID, p, hp, title string) *parse.Tree {
|
||||
id := strings.TrimSuffix(path.Base(p), ".sy")
|
||||
id := util.GetTreeID(p)
|
||||
root := &ast.Node{Type: ast.NodeDocument, ID: id, Spec: "1", Box: boxID, Path: p}
|
||||
root.SetIALAttr("title", title)
|
||||
root.SetIALAttr("id", id)
|
||||
|
|
|
@ -37,6 +37,10 @@ var (
|
|||
UserAgent = "SiYuan/" + Ver
|
||||
)
|
||||
|
||||
func GetTreeID(treePath string) string {
|
||||
return strings.TrimSuffix(path.Base(treePath), ".sy")
|
||||
}
|
||||
|
||||
func ShortPathForBootingDisplay(p string) string {
|
||||
if 25 > len(p) {
|
||||
return p
|
||||
|
|
Loading…
Add table
Reference in a new issue