Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Preserve markdown parent identity during folder import https://github.com/siyuan-note/siyuan/issues/20954

Danielf0cb72e132ed
diff --git a/kernel/model/import.go b/kernel/model/import.go
index c27efc0b3e..46e186a7d4 100644
--- a/kernel/model/import.go
+++ b/kernel/model/import.go
@@ -1598,9 +1598,11 @@ func importFromLocalPath(boxID, localPath string, toPath string, skipRoot bool)
}
// 如果当前文件夹路径下包含同名的 Markdown 文件,则不创建空文档 https://github.com/siyuan-note/siyuan/issues/13149
- if gulu.File.IsExist(currentPath+".md") || gulu.File.IsExist(currentPath+".markdown") {
- targetPaths[curRelPath+".md"] = targetPath
- return nil
+ for _, extension := range []string{".md", ".markdown"} {
+ if gulu.File.IsExist(currentPath + extension) {
+ targetPaths[curRelPath+extension] = targetPath
+ return nil
+ }
}
tree = treenode.NewTree(boxID, targetPath, hPath, title)
diff --git a/kernel/model/import_markdown_batch_fts5_test.go b/kernel/model/import_markdown_batch_fts5_test.go
index 0f133dd887..18c0b71cce 100644
--- a/kernel/model/import_markdown_batch_fts5_test.go
+++ b/kernel/model/import_markdown_batch_fts5_test.go
@@ -21,14 +21,18 @@ import (
)
func TestMarkdownImportBatchesPreserveReferencesAndEncryption(t *testing.T) {
- testMarkdownImportBatches(t, "Renamed parent")
+ testMarkdownImportBatches(t, "Renamed parent", ".md")
+}
+
+func TestMarkdownImportMarkdownParent(t *testing.T) {
+ testMarkdownImportBatches(t, "Renamed parent", ".markdown")
}
func TestStructuredTitlesMarkdownImport(t *testing.T) {
- testMarkdownImportBatches(t, "Renamed/../parent%2F")
+ testMarkdownImportBatches(t, "Renamed/../parent%2F", ".md")
}
-func testMarkdownImportBatches(t *testing.T, parentTitle string) {
+func testMarkdownImportBatches(t *testing.T, parentTitle, parentExtension string) {
t.Helper()
for _, encrypted := range []bool{false, true} {
t.Run(map[bool]string{false: "plain", true: "encrypted"}[encrypted], func(t *testing.T) {
@@ -89,7 +93,7 @@ func testMarkdownImportBatches(t *testing.T, parentTitle string) {
if err := os.MkdirAll(filepath.Join(source, "parent"), 0755); err != nil {
t.Fatal(err)
}
- if err := os.WriteFile(filepath.Join(source, "parent.md"), []byte(fmt.Sprintf("---\ndate: 2020-01-02\ntitle: %s\n---\n\n[[parent/child|child]]", parentTitle)), 0600); err != nil {
+ if err := os.WriteFile(filepath.Join(source, "parent"+parentExtension), []byte(fmt.Sprintf("---\ndate: 2020-01-02\ntitle: %s\n---\n\n[[parent/child|child]]", parentTitle)), 0600); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(source, "parent", "child.markdown"), []byte("child content"), 0600); err != nil {