I created a note in my vault meant to help me find problems in the vault. So far I have a section for finding “Dangling Links” (links to pages that don’t exist), and “Bad YAML” (frontmatter that is empty, missing, or invalid). Both are based on the kind contributions of other forum members. Do you have any similar utilities that might be useful to add? Here’s my note contents if you’d like to try the same:
---
filename: Obsidian Upkeep
aliases:
- Maintenance
- Utility
- Troubleshoot
---
# Obsidian Upkeep
## Dangling Links
```dataviewjs
const unresolved = {}
Object.entries( dv.app.metadataCache.unresolvedLinks )
.filter( ([origin, unresolvedList]) =>
Object.keys(unresolvedList).length && !origin.startsWith("Meta"))
.forEach( ([origin, unresolvedList]) => {
Object.entries( unresolvedList )
.forEach( ([newNote, count]) => {
if ( !unresolved[newNote] )
unresolved[newNote] = []
unresolved[newNote].push( dv.fileLink(origin) )
})
})
dv.table(["Non existing notes", "Linked from"],
Object.entries(unresolved)
.sort( (a, b) => (a[0].toLowerCase() < b[0].toLowerCase() ? -1 : 1) )
.map( item => [dv.fileLink( item[0] ), item[1] ] )
)
```
## Bad YAML
```dataviewjs
const result = []
for (let [fname, fcache] of Object.entries(dv.app.metadataCache.fileCache)) {
// fname is the filename
// fcache is the entry from metadataCache.fileCache
// mcache is the actual metadataCache.metadataCache entry
const mcache = dv.app.metadataCache.metadataCache[fcache.hash]
if ( (mcache && !mcache.frontmatter &&
!fname.startsWith('Meta') &&
mcache.hasOwnProperty("sections") &&
mcache["sections"].some(s => s.type == "yaml"))
|| ( mcache && mcache.frontmatter && mcache.frontmatter.notvalid )
) {
const yamlIndex = mcache["sections"].findIndex(s => s.type == "yaml")
let yamlStart, yamlEnd
// Pull out start and end, if section is found
if ( yamlIndex !== -1 ) {
yamlStart = mcache["sections"][yamlIndex]?.position.start.line
yamlEnd = mcache["sections"][yamlIndex]?.position.end.line
}
// Determine the cause of the faulty frontmatter
let cause
if ( mcache.frontmatter?.notvalid ) cause = "Not valid"
else if ( yamlIndex == -1 ) cause = "NO yaml"
else if ( yamlStart == 0 && yamlEnd == 1 ) cause = "Empty"
else cause = "Bad"
result.push([dv.fileLink(fname), cause, yamlStart ?? "", yamlEnd ?? ""])
// console.log(fname, " » ", mcache)
}
//console.log(fname, " » ", fcache, "\n »» ", mcache)
}
dv.table(["File", "Yaml status", "Start", "End"], result)
```