Skip to content

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

:art: Supports converting relative path hyperlinks into document block references after importing Markdown https://github.com/siyuan-note/siyuan/issues/13817

Daniel654020ff7d25
diff --git a/kernel/model/import.go b/kernel/model/import.go
index b49c442b7e..039a77999f 100644
--- a/kernel/model/import.go
+++ b/kernel/model/import.go
@@ -799,8 +799,9 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
moveIDs := map[string]string{}
assetsDone := map[string]string{}
if gulu.File.IsDir(localPath) { // 导入文件夹
- // 收集所有资源文件
- assets := map[string]string{}
+ targetPaths := map[string]string{}
+ count := 0
+ // md 转换 sy
filelock.Walk(localPath, func(currentPath string, d fs.DirEntry, err error) error {
if err != nil {
return err
@@ -808,9 +809,6 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
if d == nil {
return nil
}
- if localPath == currentPath {
- return nil
- }
if strings.HasPrefix(d.Name(), ".") {
if d.IsDir() {
return filepath.SkipDir
@@ -818,26 +816,20 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
return nil
}
- if !strings.HasSuffix(d.Name(), ".md") && !strings.HasSuffix(d.Name(), ".markdown") {
- assets[currentPath] = currentPath
- return nil
- }
- return nil
- })
-
- targetPaths := map[string]string{}
- count := 0
- // md 转换 sy
- filelock.Walk(localPath, func(currentPath string, d fs.DirEntry, err error) error {
- if err != nil {
- return err
- }
- if d == nil {
- return nil
- }
- if strings.HasPrefix(d.Name(), ".") {
- if d.IsDir() {
- return filepath.SkipDir
+ if !d.IsDir() && strings.Contains(filepath.ToSlash(currentPath), "/assets/") {
+ // assets 文件夹下的文件算作资源文件
+ existName := assetsDone[currentPath]
+ var name string
+ if "" == existName {
+ name = filepath.Base(currentPath)
+ name = util.FilterUploadFileName(name)
+ name = util.AssetName(name, ast.NewNodeID())
+ assetTargetPath := filepath.Join(util.DataDir, "assets", name)
+ if err = filelock.Copy(currentPath, assetTargetPath); err != nil {
+ logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", currentPath, assetTargetPath, err)
+ return nil
+ }
+ assetsDone[currentPath] = name
}
return nil
}