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

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2025-11-01 16:57:43 +08:00
parent a0f5387bb4
commit 654020ff7d
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -799,32 +799,6 @@ 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{}
filelock.Walk(localPath, func(currentPath string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d == nil {
return nil
}
if localPath == currentPath {
return nil
}
if strings.HasPrefix(d.Name(), ".") {
if d.IsDir() {
return filepath.SkipDir
}
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
@ -842,6 +816,24 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
return nil
}
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
}
var tree *parse.Tree
var ext string
title := d.Name()