🎨 Improved PDF asset file unreferenced detection https://github.com/siyuan-note/siyuan/issues/7964
This commit is contained in:
parent
02366f3c95
commit
204c3b469d
2 changed files with 20 additions and 9 deletions
|
@ -634,17 +634,15 @@ func UnusedAssets() (ret []string) {
|
|||
|
||||
for _, dest := range linkDestFilePaths {
|
||||
linkDestMap[dest] = true
|
||||
|
||||
if strings.HasSuffix(dest, ".pdf") {
|
||||
linkDestMap[dest+".sya"] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var toRemoves []string
|
||||
for asset, _ := range assetsPathMap {
|
||||
if strings.HasSuffix(asset, ".sya") {
|
||||
// 排除文件注解和对应文件
|
||||
toRemoves = append(toRemoves, asset, strings.TrimSuffix(asset, ".sya"))
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasSuffix(asset, "ocr-texts.json") {
|
||||
// 排除 OCR 结果文本
|
||||
toRemoves = append(toRemoves, asset)
|
||||
|
@ -656,8 +654,8 @@ func UnusedAssets() (ret []string) {
|
|||
}
|
||||
|
||||
dataAssetsAbsPath := util.GetDataAssetsAbsPath()
|
||||
for _, assetAbsPath := range assetsPathMap {
|
||||
if _, ok := linkDestMap[assetAbsPath]; ok {
|
||||
for dest, assetAbsPath := range assetsPathMap {
|
||||
if _, ok := linkDestMap[dest]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -704,7 +702,7 @@ func assetsLinkDestsInTree(tree *parse.Tree) (ret []string) {
|
|||
// 修改以下代码时需要同时修改 database 构造行级元素实现,增加必要的类型
|
||||
if !entering || (ast.NodeLinkDest != n.Type && ast.NodeHTMLBlock != n.Type && ast.NodeInlineHTML != n.Type &&
|
||||
ast.NodeIFrame != n.Type && ast.NodeWidget != n.Type && ast.NodeAudio != n.Type && ast.NodeVideo != n.Type &&
|
||||
!n.IsTextMarkType("a")) {
|
||||
!n.IsTextMarkType("a") && !n.IsTextMarkType("file-annotation-ref")) {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
|
@ -722,6 +720,14 @@ func assetsLinkDestsInTree(tree *parse.Tree) (ret []string) {
|
|||
|
||||
dest := strings.TrimSpace(n.TextMarkAHref)
|
||||
ret = append(ret, dest)
|
||||
} else if n.IsTextMarkType("file-annotation-ref") {
|
||||
if !isRelativePath(gulu.Str.ToBytes(n.TextMarkFileAnnotationRefID)) {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
dest := n.TextMarkFileAnnotationRefID[:strings.LastIndexByte(n.TextMarkFileAnnotationRefID, '/')]
|
||||
dest = strings.TrimSpace(dest)
|
||||
ret = append(ret, dest)
|
||||
} else {
|
||||
if ast.NodeWidget == n.Type {
|
||||
dataAssets := n.IALAttr("custom-data-assets")
|
||||
|
@ -752,6 +758,7 @@ func assetsLinkDestsInTree(tree *parse.Tree) (ret []string) {
|
|||
}
|
||||
return ast.WalkContinue
|
||||
})
|
||||
ret = gulu.Str.RemoveDuplicatedElem(ret)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -403,6 +403,10 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
|
|||
assets := assetsLinkDestsInTree(tree)
|
||||
for _, asset := range assets {
|
||||
if strings.HasPrefix(asset, "assets/") {
|
||||
if strings.Contains(asset, "?") {
|
||||
asset = asset[:strings.LastIndex(asset, "?")]
|
||||
}
|
||||
|
||||
srcAbsPath, err := GetAssetAbsPath(asset)
|
||||
if nil != err {
|
||||
logging.LogWarnf("resolve path of asset [%s] failed: %s", asset, err)
|
||||
|
|
Loading…
Add table
Reference in a new issue