An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Improve .sy.zip notebook imports https://github.com/siyuan-note/siyuan/issues/18266
Daniel594d8ac25d46
diff --git a/app/src/util/mount.ts b/app/src/util/mount.tsindex a921102b7a..b622bd9986 100644--- a/app/src/util/mount.ts+++ b/app/src/util/mount.ts@@ -109,18 +109,18 @@ export const mountHelp = () => {export const newNotebook = () => {let importObsidianHTML = "";/// #if !BROWSER- importObsidianHTML = `<div class="fn__hr"></div>- <div class="b3-label__text fn__pointer fn__flex" style="align-items: center;gap: 4px" data-type="toggle-import" role="button" tabindex="0" aria-expanded="false"><svg class="b3-list-item__arrow" style="display: block;flex: none;height: 14px;width: 14px" data-type="import-arrow"><use xlink:href="#iconRight"></use></svg><span style="line-height: 20px">${window.siyuan.languages.importFromMoreApps}</span></div>- <div class="b3-list--background fn__none" data-type="import-options" style="padding-top: 8px">- <label class="b3-list-item fn__pointer" data-type="import-sy"><svg class="b3-list-item__graphic"><use xlink:href="#iconSiYuan"></use></svg><span class="b3-list-item__text">SiYuan .sy.zip</span><input class="b3-form__upload" type="file" accept="application/zip"></label>- <div class="b3-list-item fn__pointer" data-type="import-obsidian" role="button" tabindex="0"><svg class="b3-list-item__graphic"><use xlink:href="#iconObsidian"></use></svg><span class="b3-list-item__text">Obsidian Vault</span></div>- </div>`;+ importObsidianHTML = "<div class=\"b3-list-item fn__pointer\" data-type=\"import-obsidian\" role=\"button\" tabindex=\"0\"><svg class=\"b3-list-item__graphic\"><use xlink:href=\"#iconObsidian\"></use></svg><span class=\"b3-list-item__text\">Obsidian Vault</span></div>";/// #endifconst dialog = new Dialog({title: window.siyuan.languages.newNotebook,content: `<div class="b3-dialog__content"><input placeholder="${window.siyuan.languages.notebookName}" class="b3-text-field fn__block">- ${importObsidianHTML}+ <div class="fn__hr"></div>+ <div class="b3-label__text fn__pointer fn__flex" style="align-items: center;gap: 4px" data-type="toggle-import" role="button" tabindex="0" aria-expanded="false"><svg class="b3-list-item__arrow" style="display: block;flex: none;height: 14px;width: 14px" data-type="import-arrow"><use xlink:href="#iconRight"></use></svg><span style="line-height: 20px">${window.siyuan.languages.importFromMoreApps}</span></div>+ <div class="b3-list--background fn__none" data-type="import-options" style="padding-top: 8px">+ <label class="b3-list-item fn__pointer" data-type="import-sy"><svg class="b3-list-item__graphic"><use xlink:href="#iconSiYuan"></use></svg><span class="b3-list-item__text">SiYuan .sy.zip</span><input class="b3-form__upload" type="file" accept="application/zip"></label>+ ${importObsidianHTML}+ </div></div><div class="b3-dialog__action"><button class="b3-button b3-button--cancel" data-type="cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>@@ -148,7 +148,6 @@ export const newNotebook = () => {});dialog.destroy();});- /// #if !BROWSERconst toggleImportElement = dialog.element.querySelector('[data-type="toggle-import"]') as HTMLElement;const importOptionsElement = dialog.element.querySelector('[data-type="import-options"]') as HTMLElement;const importArrowElement = toggleImportElement.querySelector('[data-type="import-arrow"]') as SVGElement;@@ -175,6 +174,7 @@ export const newNotebook = () => {dialog.destroy();fetchPost("/api/import/importSYNotebook", formData);});+ /// #if !BROWSERconst importObsidianElement = dialog.element.querySelector('[data-type="import-obsidian"]') as HTMLElement;let selectingObsidianVault = false;const selectObsidianVault = async () => {diff --git a/kernel/model/blockial.go b/kernel/model/blockial.goindex 1c55bdb740..d35646b605 100644--- a/kernel/model/blockial.go+++ b/kernel/model/blockial.go@@ -163,7 +163,6 @@ func BatchSetBlockAttrs(blockAttrs []map[string]any) (err error) {attrs := blockAttr["attrs"].(map[string]string)if IsBoxDoc(tree.Box, tree.ID) {- attrs[BoxDocAttr] = tree.Boxattrs[DocHiddenAttr] = "true"if icon, ok := attrs["icon"]; ok {boxIcons[tree.Box] = filterBoxIcon(icon)@@ -223,7 +222,6 @@ func SetBlockAttrs(id string, nameValues map[string]string) (err error) {}if IsBoxDoc(tree.Box, tree.ID) {- nameValues[BoxDocAttr] = tree.BoxnameValues[DocHiddenAttr] = "true"if icon, ok := nameValues["icon"]; ok {nameValues["icon"] = filterBoxIcon(icon)diff --git a/kernel/model/box_doc.go b/kernel/model/box_doc.goindex 180086b7c6..ff37788c3d 100644--- a/kernel/model/box_doc.go+++ b/kernel/model/box_doc.go@@ -40,7 +40,6 @@ import (const (boxDocMetaSpec = 1boxDocMetaName = "boxDoc.json"- BoxDocAttr = "custom-sy-box-doc")type boxDocMeta struct {@@ -174,7 +173,7 @@ func ensureBoxDoc0(boxID string) (boxDocID string, err error) {return}- boxDocID, err = findBoxDocByMarker(box)+ boxDocID, err = findBoxDoc(box)if err != nil {return "", err}@@ -210,19 +209,12 @@ func RefreshBoxDocFeature() {ReloadFiletree()}-func findBoxDocByMarker(box *Box) (ret string, err error) {+func findBoxDoc(box *Box) (ret string, err error) {boxDocID := deterministicBoxDocID(box.ID)if "" == boxDocID || !box.Exist(boxDocPath(boxDocID)) {return}- tree, err := filesys.LoadTree(box.ID, boxDocPath(boxDocID), util.NewLute())- if err != nil {- return "", err- }- if box.ID == tree.Root.IALAttr(BoxDocAttr) {- ret = boxDocID- }- return+ return boxDocID, nil}func createBoxDoc(box *Box, boxDocID string) error {@@ -233,7 +225,6 @@ func createBoxDoc(box *Box, boxDocID string) error {}p := boxDocPath(boxDocID)tree := treenode.NewTree(box.ID, p, "/"+title, html.EscapeAttrVal(title))- tree.Root.SetIALAttr(BoxDocAttr, box.ID)tree.Root.SetIALAttr(DocHiddenAttr, "true")if "" != boxConf.Icon {tree.Root.SetIALAttr("icon", boxConf.Icon)@@ -270,14 +261,13 @@ func reconcileBoxDoc(box *Box, boxDocID string) error {title = Conf.Language(16)}titleChanged := tree.Root.IALAttr("title") != title- changed := titleChanged || tree.HPath != "/"+title || tree.Root.IALAttr(BoxDocAttr) != box.ID ||- tree.Root.IALAttr(DocHiddenAttr) != "true" || tree.Root.IALAttr("icon") != boxConf.Icon+ changed := titleChanged || tree.HPath != "/"+title || tree.Root.IALAttr(DocHiddenAttr) != "true" ||+ tree.Root.IALAttr("icon") != boxConf.Iconif !changed {return nil}tree.HPath = "/" + titletree.Root.SetIALAttr("title", title)- tree.Root.SetIALAttr(BoxDocAttr, box.ID)tree.Root.SetIALAttr(DocHiddenAttr, "true")if "" == boxConf.Icon {tree.Root.RemoveIALAttr("icon")@@ -387,10 +377,9 @@ func setBoxDocIcon(boxID, icon string) error {return nil}-func removeBoxDocAttrs(tree *parse.Tree) {+func removeBoxDocHiddenAttr(tree *parse.Tree) {if nil == tree || nil == tree.Root {return}- tree.Root.RemoveIALAttr(BoxDocAttr)tree.Root.RemoveIALAttr(DocHiddenAttr)}diff --git a/kernel/model/file.go b/kernel/model/file.goindex 4df1d159ae..eedbc2dd91 100644--- a/kernel/model/file.go+++ b/kernel/model/file.go@@ -1049,7 +1049,7 @@ func DuplicateDoc(tree *parse.Tree) {previousPath := tree.PathresetTree(tree, "Duplicated", false)if isBoxDoc {- removeBoxDocAttrs(tree)+ removeBoxDocHiddenAttr(tree)}ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {diff --git a/kernel/model/import.go b/kernel/model/import.goindex 69ce2bb633..f541938fd1 100644--- a/kernel/model/import.go+++ b/kernel/model/import.go@@ -50,6 +50,7 @@ import ("github.com/siyuan-note/logging""github.com/siyuan-note/riff""github.com/siyuan-note/siyuan/kernel/av"+ "github.com/siyuan-note/siyuan/kernel/cache""github.com/siyuan-note/siyuan/kernel/conf""github.com/siyuan-note/siyuan/kernel/filesys""github.com/siyuan-note/siyuan/kernel/sql"@@ -296,10 +297,9 @@ func importSY(zipPath, boxID, toPath string, createNotebook bool) (createdBoxIDtree.Path = filepath.ToSlash(strings.TrimPrefix(syPath, unzipRootPath))if createNotebook && oldRootID == importedBoxDocID {importedBoxDoc = true- tree.Root.SetIALAttr(BoxDocAttr, boxID)tree.Root.SetIALAttr(DocHiddenAttr, "true")- } else if "" != tree.Root.IALAttr(BoxDocAttr) {- removeBoxDocAttrs(tree)+ } else if oldRootID == importedBoxDocID {+ removeBoxDocHiddenAttr(tree)}trees[tree.ID] = treeutil.PushEndlessProgress(Conf.language(73) + " " + fmt.Sprintf(Conf.language(70), fmt.Sprintf("%d/%d", i+1, len(syPaths))))@@ -854,6 +854,8 @@ func importSY(zipPath, boxID, toPath string, createNotebook bool) (createdBoxIDabsPath := filepath.Join(targetDir, treePath)p := strings.TrimPrefix(absPath, boxAbsPath)p = filepath.ToSlash(p)+ cache.RemoveTreeDataInBox(util.GetTreeID(p), boxID)+ cache.RemoveDocIALInBox(p, boxID)tree, err := filesys.LoadTree(boxID, p, luteEngine)if err != nil {logging.LogErrorf("load tree [%s] failed: %s", treePath, err)@@ -867,6 +869,7 @@ func importSY(zipPath, boxID, toPath string, createNotebook bool) (createdBoxID}treenode.IndexBlockTree(tree)+ cache.PutDocIALInBox(tree.Path, tree.Box, parse.IAL2Map(tree.Root.KramdownIAL))var avNodes []*ast.Nodefor _, avNode := range tree.Root.ChildrenByType(ast.NodeAttributeView) {if _, ok := importedAvIDs[avNode.AttributeViewID]; ok {diff --git a/kernel/model/transaction.go b/kernel/model/transaction.goindex b8873afccf..36cd67c88d 100644--- a/kernel/model/transaction.go+++ b/kernel/model/transaction.go@@ -1915,7 +1915,6 @@ func (tx *Transaction) doSetAttrs(operation *Operation) (ret *TxErr) {return &TxErr{code: TxErrCodeBlockNotFound, id: id}}if IsBoxDoc(tree.Box, tree.ID) {- attrs[BoxDocAttr] = tree.Boxattrs[DocHiddenAttr] = "true"if icon, ok := attrs["icon"]; ok {icon = filterBoxIcon(icon)