🎨 新建文档名模板 改为 新建文档存放位置 并支持设置路径 https://github.com/siyuan-note/siyuan/issues/4494

This commit is contained in:
Liang Ding 2023-02-03 20:47:43 +08:00
parent f3aa37f21c
commit 551cbb8c18
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
14 changed files with 38 additions and 41 deletions

View file

@ -517,7 +517,7 @@ func lockFile(c *gin.Context) {
}
}
func getDocNameTemplate(c *gin.Context) {
func getDocCreateSavePath(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
@ -528,22 +528,22 @@ func getDocNameTemplate(c *gin.Context) {
notebook := arg["notebook"].(string)
box := model.Conf.Box(notebook)
nameTemplate := model.Conf.FileTree.CreateDocNameTemplate
docCreateSavePathTpl := model.Conf.FileTree.DocCreateSavePath
if nil != box {
nameTemplate = box.GetConf().CreateDocNameTemplate
docCreateSavePathTpl = box.GetConf().DocCreateSavePath
}
if "" == nameTemplate {
nameTemplate = model.Conf.FileTree.CreateDocNameTemplate
if "" == docCreateSavePathTpl {
docCreateSavePathTpl = model.Conf.FileTree.DocCreateSavePath
}
name, err := model.RenderGoTemplate(nameTemplate)
path, err := model.RenderGoTemplate(docCreateSavePathTpl)
if nil != err {
ret.Code = -1
ret.Msg = err.Error()
return
}
ret.Data = map[string]interface{}{
"name": name,
"path": path,
}
}

View file

@ -86,7 +86,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/filetree/searchDocs", model.CheckAuth, searchDocs)
ginServer.Handle("POST", "/api/filetree/listDocsByPath", model.CheckAuth, listDocsByPath)
ginServer.Handle("POST", "/api/filetree/getDoc", model.CheckAuth, getDoc)
ginServer.Handle("POST", "/api/filetree/getDocNameTemplate", model.CheckAuth, getDocNameTemplate)
ginServer.Handle("POST", "/api/filetree/getDocCreateSavePath", model.CheckAuth, getDocCreateSavePath)
ginServer.Handle("POST", "/api/filetree/getRefCreateSavePath", model.CheckAuth, getRefCreateSavePath)
ginServer.Handle("POST", "/api/filetree/changeSort", model.CheckAuth, changeSort)
ginServer.Handle("POST", "/api/filetree/lockFile", model.CheckAuth, lockFile)

View file

@ -22,8 +22,8 @@ type BoxConf struct {
Sort int `json:"sort"` // 排序字段
Icon string `json:"icon"` // 图标
Closed bool `json:"closed"` // 是否处于关闭状态
RefCreateSavePath string `json:"refCreateSavePath"` // 块引时新建文档存储文件夹路径
CreateDocNameTemplate string `json:"createDocNameTemplate"` // 新建文档名模板
RefCreateSavePath string `json:"refCreateSavePath"` // 块引时新建文档存储路径
DocCreateSavePath string `json:"docCreateSavePath"` // 新建文档存储路径
DailyNoteSavePath string `json:"dailyNoteSavePath"` // 新建日记存储路径
DailyNoteTemplatePath string `json:"dailyNoteTemplatePath"` // 新建日记使用的模板路径
}
@ -32,8 +32,6 @@ func NewBoxConf() *BoxConf {
return &BoxConf{
Name: "Untitled",
Closed: true,
RefCreateSavePath: "",
CreateDocNameTemplate: "",
DailyNoteSavePath: "/daily note/{{now | date \"2006/01\"}}/{{now | date \"2006-01-02\"}}",
DailyNoteTemplatePath: "",
}

View file

@ -23,8 +23,8 @@ import (
type FileTree struct {
AlwaysSelectOpenedFile bool `json:"alwaysSelectOpenedFile"` // 是否自动选中当前打开的文件
OpenFilesUseCurrentTab bool `json:"openFilesUseCurrentTab"` // 在当前页签打开文件
RefCreateSavePath string `json:"refCreateSavePath"` // 块引时新建文档存储文件夹路径
CreateDocNameTemplate string `json:"createDocNameTemplate"` // 新建文档名模板
RefCreateSavePath string `json:"refCreateSavePath"` // 块引时新建文档存储路径
DocCreateSavePath string `json:"docCreateSavePath"` // 新建文档存储路径
MaxListCount int `json:"maxListCount"` // 最大列出数量
MaxOpenTabCount int `json:"maxOpenTabCount"` // 最大打开页签数量
AllowCreateDeeper bool `json:"allowCreateDeeper"` // 允许创建超过 7 层深度的子文档
@ -39,7 +39,6 @@ func NewFileTree() *FileTree {
AlwaysSelectOpenedFile: false,
OpenFilesUseCurrentTab: false,
Sort: util.SortModeCustom,
CreateDocNameTemplate: "",
MaxListCount: 512,
MaxOpenTabCount: 8,
AllowCreateDeeper: false,