本库的宏观统计数据

let allFiles = dv.pages()

let ftMd = allFiles.file.sort(t => t.cday)[0]
let total = parseInt([new Date() - ftMd.ctime] / (60*60*24*1000))
dv.paragraph(`已使用obsidian **${total}** 天`)

dv.paragraph(`文件总数 **${allFiles.length}** 个`)

dv.span(`标签 **${allFiles.file.tags.distinct().length}** 个`)
dv.span("; ")
dv.span(`文件夹数 **${allFiles.file.folder.distinct().length}** 个`)
dv.span("; ")
dv.span(`文件别名 **${allFiles.file.aliases.distinct().length}** 个`)


// 统计未创建链接文件的正向链接总数,即broken links counts
const unresolvedLinks  = Object.values(app.metadataCache.unresolvedLinks)
.filter(unresolved => Object.keys(unresolved).length > 0 )
.flatMap(unresolved => Object.keys(unresolved))
.map(f => "<span title='There is no note that matches this link.' class='invalid-link'>  <span class='invalid-link-brackets'>[[</span>  " + f + "  <span class='invalid-link-brackets'>]]</span></span>");
//console.log(unresolvedLinks)

// 统计入链数为0的文件数,即未被其他页面引用的文件数,即orphaned files counts
const orphanedFiles = allFiles.filter(f => f.file.inlinks.length==0)
//console.log(orphanedFiles)


dv.paragraph("\n")
dv.span(`正向链接 **${allFiles.file.outlinks.length}** 个`)
dv.span("; ")
dv.span(`未创建 **${unresolvedLinks.length}** 个`)

dv.paragraph("\n")
dv.span(`反向链接 **${allFiles.file.inlinks.length}** 个`)
dv.span("; ")
dv.span(`孤立文件 **${orphanedFiles.length}** 个`)


let mocFiles = dv.pages("#索引笔记")
let tocFiles = dv.pages("#目录笔记")

dv.paragraph(`MOC文件 **${mocFiles.length}** 个,TOC文件 **${tocFiles.length}** 个`)

let ankiFiles = dv.pages("#复习回顾")
let todoFiles = dv.pages("#待办")

dv.paragraph(`anki卡片 **${ankiFiles.length}** 个,待办文件 **${todoFiles.length}** 个`)





反向链接: