🎨 支持笔记本设置独立的排序规则 https://github.com/siyuan-note/siyuan/issues/3623

This commit is contained in:
Liang Ding 2023-02-04 16:56:51 +08:00
parent 002dbb02b3
commit 2b0788db6c
No known key found for this signature in database
GPG key ID: 136F30F901A2231D

View file

@ -20,8 +20,6 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"github.com/siyuan-note/siyuan/kernel/task"
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -41,6 +39,7 @@ import (
"github.com/siyuan-note/logging" "github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/conf" "github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/sql" "github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/task"
"github.com/siyuan-note/siyuan/kernel/treenode" "github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util" "github.com/siyuan-note/siyuan/kernel/util"
) )
@ -51,6 +50,7 @@ type Box struct {
Name string `json:"name"` Name string `json:"name"`
Icon string `json:"icon"` Icon string `json:"icon"`
Sort int `json:"sort"` Sort int `json:"sort"`
SortMode int `json:"sortMode"`
Closed bool `json:"closed"` Closed bool `json:"closed"`
historyGenerated int64 // 最近一次历史生成时间 historyGenerated int64 // 最近一次历史生成时间
@ -127,6 +127,7 @@ func ListNotebooks() (ret []*Box, err error) {
Name: boxConf.Name, Name: boxConf.Name,
Icon: boxConf.Icon, Icon: boxConf.Icon,
Sort: boxConf.Sort, Sort: boxConf.Sort,
SortMode: boxConf.SortMode,
Closed: boxConf.Closed, Closed: boxConf.Closed,
}) })
} }
@ -226,12 +227,18 @@ func (box *Box) Ls(p string) (ret []*FileInfo, totals int, err error) {
} }
} }
files, err := ioutil.ReadDir(filepath.Join(util.DataDir, box.ID, p)) entries, err := os.ReadDir(filepath.Join(util.DataDir, box.ID, p))
if nil != err { if nil != err {
return return
} }
for _, f := range files { for _, f := range entries {
info, infoErr := f.Info()
if nil != infoErr {
logging.LogErrorf("read file info failed: %s", infoErr)
continue
}
name := f.Name() name := f.Name()
if util.IsReservedFilename(name) { if util.IsReservedFilename(name) {
continue continue
@ -246,7 +253,7 @@ func (box *Box) Ls(p string) (ret []*FileInfo, totals int, err error) {
fi := &FileInfo{} fi := &FileInfo{}
fi.name = name fi.name = name
fi.isdir = f.IsDir() fi.isdir = f.IsDir()
fi.size = f.Size() fi.size = info.Size()
fPath := path.Join(p, name) fPath := path.Join(p, name)
if f.IsDir() { if f.IsDir() {
fPath += "/" fPath += "/"