mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 Improve exporting/importing .sy.zip https://github.com/siyuan-note/siyuan/issues/13531
This commit is contained in:
parent
a3fec2c9e8
commit
77fa89010f
3 changed files with 37 additions and 2 deletions
|
|
@ -961,6 +961,12 @@ func MissingAssets() (ret []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func emojisInTree(tree *parse.Tree) (ret []string) {
|
func emojisInTree(tree *parse.Tree) (ret []string) {
|
||||||
|
if icon := tree.Root.IALAttr("icon"); "" != icon {
|
||||||
|
if !strings.Contains(icon, "://") && !strings.HasPrefix(icon, "api/icon/") {
|
||||||
|
ret = append(ret, "/emojis/"+icon)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
if !entering {
|
if !entering {
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
|
|
|
||||||
|
|
@ -751,7 +751,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
|
||||||
from := filepath.Join(util.DataDir, emoji)
|
from := filepath.Join(util.DataDir, emoji)
|
||||||
to := filepath.Join(savePath, emoji)
|
to := filepath.Join(savePath, emoji)
|
||||||
if err := filelock.Copy(from, to); err != nil {
|
if err := filelock.Copy(from, to); err != nil {
|
||||||
logging.LogErrorf("copy emojis from [%s] to [%s] failed: %s", from, savePath, err)
|
logging.LogErrorf("copy emojis from [%s] to [%s] failed: %s", from, to, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -909,7 +909,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do
|
||||||
from := filepath.Join(util.DataDir, emoji)
|
from := filepath.Join(util.DataDir, emoji)
|
||||||
to := filepath.Join(savePath, emoji)
|
to := filepath.Join(savePath, emoji)
|
||||||
if err := filelock.Copy(from, to); err != nil {
|
if err := filelock.Copy(from, to); err != nil {
|
||||||
logging.LogErrorf("copy emojis from [%s] to [%s] failed: %s", from, savePath, err)
|
logging.LogErrorf("copy emojis from [%s] to [%s] failed: %s", from, to, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1722,6 +1722,16 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
||||||
|
|
||||||
copiedAssets.Add(asset)
|
copiedAssets.Add(asset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 复制自定义表情图片
|
||||||
|
emojis := emojisInTree(tree)
|
||||||
|
for _, emoji := range emojis {
|
||||||
|
from := filepath.Join(util.DataDir, emoji)
|
||||||
|
to := filepath.Join(exportFolder, emoji)
|
||||||
|
if copyErr := filelock.Copy(from, to); copyErr != nil {
|
||||||
|
logging.LogErrorf("copy emojis from [%s] to [%s] failed: %s", from, to, copyErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导出数据库 Attribute View export https://github.com/siyuan-note/siyuan/issues/8710
|
// 导出数据库 Attribute View export https://github.com/siyuan-note/siyuan/issues/8710
|
||||||
|
|
|
||||||
|
|
@ -554,6 +554,25 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
||||||
os.RemoveAll(assets)
|
os.RemoveAll(assets)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 将包含的自定义表情统一移动到 data/emojis/ 下
|
||||||
|
var emojiDirs []string
|
||||||
|
filelock.Walk(unzipRootPath, func(path string, d fs.DirEntry, err error) error {
|
||||||
|
if strings.Contains(path, "emojis") && d.IsDir() {
|
||||||
|
emojiDirs = append(emojiDirs, path)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
dataEmojis := filepath.Join(util.DataDir, "emojis")
|
||||||
|
for _, emojis := range emojiDirs {
|
||||||
|
if gulu.File.IsDir(emojis) {
|
||||||
|
if err = filelock.Copy(emojis, dataEmojis); err != nil {
|
||||||
|
logging.LogErrorf("copy emojis from [%s] to [%s] failed: %s", emojis, dataEmojis, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os.RemoveAll(emojis)
|
||||||
|
}
|
||||||
|
|
||||||
var baseTargetPath string
|
var baseTargetPath string
|
||||||
if "/" == toPath {
|
if "/" == toPath {
|
||||||
baseTargetPath = "/"
|
baseTargetPath = "/"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue