An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve edge cases for empty titles (#17895)
Jeffrey Chend840b44d720a
diff --git a/app/src/util/newFile.ts b/app/src/util/newFile.tsindex 2cecbba738..b85fc19afe 100644--- a/app/src/util/newFile.ts+++ b/app/src/util/newFile.ts@@ -95,14 +95,17 @@ export const newFile = (optios: {if (!optios.useSavePath) {data.data.box = optios.notebookId;}+ const docName = optios.name || window.siyuan.languages._kernel[16];+ const titleEmpty = !optios.name;if ((data.data.path.indexOf("/") > -1 && optios.useSavePath) || optios.name) {if (data.data.path.startsWith("/") || optios.currentPath === "/") {- const createPath = pathPosix().join(data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : ""));+ const createPath = pathPosix().join(data.data.path, docName);fetchPost("/api/filetree/createDocWithMd", {notebook: data.data.box,path: createPath,// 根目录时无法确定 parentIDmarkdown: "",+ titleEmpty,listDocTree: optios.listDocTree}, response => {if (optios.afterCB) {@@ -123,12 +126,13 @@ export const newFile = (optios: {notebook: data.data.box,path: optios.notebookId === data.data.box ? (optios.currentPath.endsWith(".sy") ? optios.currentPath : optios.currentPath + ".sy") : (data.data.path || "/")}, (responseHPath) => {- const createPath = pathPosix().join(responseHPath.data, data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : ""));+ const createPath = pathPosix().join(responseHPath.data, data.data.path, docName);fetchPost("/api/filetree/createDocWithMd", {notebook: data.data.box,path: createPath,parentID: getDisplayName(optios.currentPath, true, true),markdown: "",+ titleEmpty,listDocTree: optios.listDocTree}, response => {if (optios.afterCB) {@@ -147,16 +151,17 @@ export const newFile = (optios: {});}} else {- const title = pathPosix().basename(data.data.path || window.siyuan.languages.untitled);+ const title = pathPosix().basename(data.data.path);if (!validateName(title)) {return;}if (optios.notebookId !== data.data.box) {- const createPath = pathPosix().join(data.data.path || "/", optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : ""));+ const createPath = pathPosix().join(data.data.path || "/", docName);fetchPost("/api/filetree/createDocWithMd", {notebook: data.data.box,path: createPath,markdown: "",+ titleEmpty,listDocTree: optios.listDocTree}, response => {if (optios.afterCB) {@@ -236,13 +241,13 @@ export const newFileByName = (app: App, value: string) => {newFile({app,useSavePath: true,- name: replaceFileName(value.trim()) || window.siyuan.languages.untitled+ name: replaceFileName(value.trim())});};export const newFileBySelect = (protyle: IProtyle, selectText: string, nodeElement: HTMLElement, pathDir: string, targetNotebookId: string) => {- const newFileName = replaceFileName(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML).replace(/\n/g, "").trim()) || window.siyuan.languages.untitled;- const hPath = pathPosix().join(pathDir, newFileName);+ const newFileName = replaceFileName(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML).replace(/\n/g, "").trim());+ const hPath = pathPosix().join(pathDir, newFileName || window.siyuan.languages._kernel[16]);fetchPost("/api/filetree/getIDsByHPath", {path: hPath,notebook: targetNotebookId@@ -261,7 +266,8 @@ export const newFileBySelect = (protyle: IProtyle, selectText: string, nodeElemenotebook: targetNotebookId,path: hPath,parentID: protyle.notebookId === targetNotebookId ? protyle.block.rootID : "",- markdown: ""+ markdown: "",+ titleEmpty: newFileName === "",}, response => {const refElement = protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {type: "id",diff --git a/kernel/model/file.go b/kernel/model/file.goindex b6df71f400..574870b4e3 100644--- a/kernel/model/file.go+++ b/kernel/model/file.go@@ -1064,7 +1064,7 @@ func CreateDocByMd(boxID, p, title, md string, sorts []string, arg map[string]anluteEngine := util.NewLute()dom := luteEngine.Md2BlockDOM(md, false)- tree, err = createDoc(box.ID, p, title, dom)+ tree, err = createDoc(box.ID, p, title, dom, false)if err != nil {return}@@ -1102,7 +1102,13 @@ func CreateWithMarkdown(tags, boxID, hPath, md, parentID, id string, withMath boenableLuteInlineSyntax(luteEngine)}dom := luteEngine.Md2BlockDOM(md, false)- retID, err = createDocsByHPath(box.ID, hPath, dom, parentID, id)+ titleEmpty := false+ if nil != arg {+ if titleEmptyArg, ok := arg["titleEmpty"]; ok {+ titleEmpty = titleEmptyArg.(bool)+ }+ }+ retID, err = createDocsByHPath(box.ID, hPath, dom, parentID, id, titleEmpty)nameValues := map[string]string{}tags = strings.TrimSpace(tags)@@ -1181,7 +1187,7 @@ func CreateDailyNote(boxID string) (p string, existed bool, err error) {return}- id, err := createDocsByHPath(box.ID, hPath, "", "", "")+ id, err := createDocsByHPath(box.ID, hPath, "", "", "", false)if err != nil {return}@@ -1783,7 +1789,7 @@ func RenameDoc(boxID, p, title string) (err error) {return}-func createDoc(boxID, p, title, dom string) (tree *parse.Tree, err error) {+func createDoc(boxID, p, title, dom string, titleEmpty bool) (tree *parse.Tree, err error) {title = normalizeDocTitle(title)if 512 < utf8.RuneCountInString(title) {// 限制笔记本名和文档名最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299@@ -1794,6 +1800,8 @@ func createDoc(boxID, p, title, dom string) (tree *parse.Tree, err error) {if "" == title {title = Conf.Language(16)isEmpty = true+ } else if titleEmpty {+ isEmpty = true}baseName := strings.TrimSpace(path.Base(p))diff --git a/kernel/model/path.go b/kernel/model/path.goindex 3d188e8480..5a6c138659 100644--- a/kernel/model/path.go+++ b/kernel/model/path.go@@ -33,7 +33,7 @@ import ("github.com/siyuan-note/siyuan/kernel/util")-func createDocsByHPath(boxID, hPath, content, parentID, id string) (retID string, err error) {+func createDocsByHPath(boxID, hPath, content, parentID, id string, titleEmpty bool) (retID string, err error) {if "" == id {id = ast.NewNodeID()}@@ -50,7 +50,7 @@ func createDocsByHPath(boxID, hPath, content, parentID, id string) (retID stringif nil != preferredParent && preferredParent.RootID == parentID {// 如果父文档存在且 ID 一致,则直接在父文档下创建p := strings.TrimSuffix(preferredParent.Path, ".sy") + "/" + id + ".sy"- if _, err = createDoc(boxID, p, name, content); err != nil {+ if _, err = createDoc(boxID, p, name, content, titleEmpty); err != nil {logging.LogErrorf("create doc [%s] failed: %s", p, err)}return@@ -102,11 +102,11 @@ func createDocsByHPath(boxID, hPath, content, parentID, id string) (retID stringpathBuilder.WriteString(rootID)docP := pathBuilder.String() + ".sy"if isNotLast {- if _, err = createDoc(boxID, docP, part, ""); err != nil {+ if _, err = createDoc(boxID, docP, part, "", false); err != nil {return}} else {- if _, err = createDoc(boxID, docP, part, content); err != nil {+ if _, err = createDoc(boxID, docP, part, content, titleEmpty); err != nil {return}}