mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 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:
parent
a0f5387bb4
commit
654020ff7d
1 changed files with 18 additions and 26 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue