Unresolved links which are aliased somewhere
So here is a script which lists unresolved links which are aliased in an existing files:
## Unresolved links which are aliased in an existing file
```dataviewjs
// Build the list of all existing aliases in the vault,
// with references to every file it's defined in
const aliasToPaths = {} // alias to file.path(s)
await dv.pages()
.where(p => p.file.aliases.length > 0)
.forEach(p => {
p.file.aliases.forEach( a => {
if ( !(a in aliasToPaths ) )
aliasToPaths[a] = []
aliasToPaths[a].push(p.file.path)
})
})
// Build the complete list of unresolved notes,
// with where they're defined as the origin
const unresolved = {}
Object.entries( dv.app.metadataCache.unresolvedLinks )
.filter( ([origin, unresolvedList]) =>
Object.keys(unresolvedList).length )
.forEach( ([origin, unresolvedList]) => {
Object.entries( unresolvedList )
.forEach( ([newNote, count]) => {
if ( !unresolved[newNote] )
unresolved[newNote] = []
unresolved[newNote].push( dv.fileLink(origin) )
})
})
// Combine the two and list all unresolved notes,
// with a column listing where they're defined,
// and a column with where their alias is defined
dv.table(["Unresolved", "Origin(s)", "Aliased in"],
Object.entries(unresolved)
.sort( (a, b) => (a[0].toLowerCase() < b[0].toLowerCase() ? -1 : 1) )
.map( item => [dv.fileLink( item[0] ),
item[1],
( aliasToPaths[ item[0] ] ?
aliasToPaths[ item[0] ].map( p => dv.fileLink(p) ) :
"" ) ] )
.filter( row => row[2] )
)
```
In my test vault this lists the following:
How to read this table:
- Neither “Johnny Boy” nor “SameSame” exists as separate notes in my test vault
- Someone™ linked to “Johnny Boy” from “f52147 Nested tables” and “Sandbox”
- Someone™ linked to “SameSame” from “SameName”
- “Johnny Boy” is listed as an alias within the note “John Tucker Doe”
- “SameSame” is listed as an alias in both “SameName” and “Jane Smith”
- Someone™ is a little confused when creating notes and aliases…
Adaption to list origin of all unresolved files
To list the origin of all unresolved files, one can use the script below, where I’ve removed the alias references, and removed the column from the output table. If one would want to combine both of these result one could remove the .filter(row => row[2])
close to the bottom.
But if one just want the full list of unresolved files with their origin, one could use this script:
```dataviewjs
// Build the complete list of unresolved notes,
// with where they're defined as the origin
const unresolved = {}
Object.entries( dv.app.metadataCache.unresolvedLinks )
.filter( ([origin, unresolvedList]) =>
Object.keys(unresolvedList).length )
.forEach( ([origin, unresolvedList]) => {
Object.entries( unresolvedList )
.forEach( ([newNote, count]) => {
if ( !unresolved[newNote] )
unresolved[newNote] = []
unresolved[newNote].push( dv.fileLink(origin) )
})
})
// Combine the two and list all unresolved notes,
// with a column listing where they're defined
dv.table(["Unresolved", "Origin(s)"],
Object.entries(unresolved)
.sort( (a, b) => (a[0].toLowerCase() < b[0].toLowerCase() ? -1 : 1) )
.map( item => [dv.fileLink( item[0] ), item[1] ] )
)
```
In my test vault the top of the output from this is:
Here one can see that I’ve got some random links to dates which are not resolved (aka non-existing), referred to from various workout notes.
I hope this is helpful to someone passing by this thread, and even though this is a feature request, I think this also helps to showcase one part of what’s asked for in this request.
It should be easy to see that given the unresolved link to “John Doe”, it would show up in this list with an aliased in “John Tucker Doe” (in the last column), and from there one could rather easily change the reference to the existing link.