List all linked-to nonexistent files #1211
Replies: 2 comments 9 replies
-
What do you mean by "missing links"? Do you mean links to non-existent files? |
Beta Was this translation helpful? Give feedback.
-
/*
unresolvedLinks: Record<
SourceFilename extends string,
Record<
brokenLinkName extends string,
brokenLinkCount extends number
>
> as BrokenLinkNameToCount
const exampleUnresolvedLinksValue: BrokenLinkNameToCount = {
"i_dont_exist.md" : 1
}
A) currently: dv.app.metadataCache.unresolvedLinks = {
"insert_file_path": NonEmptyObject,
"other_stuff": EmptyObject
}
B) i-want-a-dataview-proper-format:
unresolvedLinks : [ [NonEmptyObject.key, nonEmptyObject.values], ... ]
// other_stuff and its EmptyObject is removed.
*/
// --- DATA LAYER BOUNDARY
// type unresolvedTuples: UnResolvedTuple[]
// type UnresolvedTuple = [sourceFileName, BrokenLinkNameToCount] where BrokenLinkNameToCount is nonEmpty
// purpose: exclude empty objects from our unresolved tuples list.
const unresolvedLinkTuples = Object.entries(
dv.app?.metadataCache?.unresolvedLinks || {}
);
// --- BUSINESS LOGIC BOUNDARY
const thresholdedUnresolvedTuples = unresolvedLinkTuples.filter(
([sourceFileName, brokenLinkNameToCountMapping]) => {
return Object.keys(brokenLinkNameToCountMapping).length;
}
);
const transformedTuples = thresholdedUnresolvedTuples;
// RENDERING LOGIC BOUNDARY
const sourceFileNameAndLinkNamesTuples = transformedTuples.map(
([sourceFileName, linkNameToCountContext]) => {
const linkNames = Object.entries(linkNameToCountContext).map(
keepOnlyKeyFromTupleMapPredicate
);
return [sourceFileName, linkNames];
}
);
const sourceFileLinkAndLinkNamesTuples = sourceFileNameAndLinkNamesTuples.map(
([sourceFileName, linkNames]) => {
const sourceFileLink = dv.fileLink(sourceFileName);
return [sourceFileLink, linkNames];
}
);
const headers = ["source-link", "non-existent-link-name"];
dv.table(headers, dv.array(sourceFileLinkAndLinkNamesTuples));
function keepOnlyKeyFromTupleMapPredicate([key]) {
return key;
} I think its easier to read if the logic is split up, and use better variable names. i can't read k, v stuff i wrote after 2 months later. Then, for the ignorePaths then you would iterate over each keyvalue tuple of your unresolvedTuples, grab the valueTuple which contains a RecordType, grab the key of that recordType which contains the full path of the unresolved link, and filter out any fullpath that is included in your filepaths. ignorePaths.some(ignorePath => brokeLinkpath.startsWith(ignorePath) Because the starting object is unresolved links from the cache, its not gonna be huge. There's no need to push all the logic together. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'd like to get an overview over missing links in my vault, and found the following DVJS-query for doing so:
In theory, this would be as simple as setting
count=1
. But... that results in 573 entries. Which is.... way too many, and a lot of them are meaningless files I don't care about in the scope of this.Because it is too unprecise, there are certain subfolders and/or filenames I want to exclude. And, as far as I could test, adding any filename to
ignoredNonExisting
does not actually exclude them.Query taken from DataviewJS Snippet Showcase on the forums.
So what I need help with is equipping this snippet with
And preferably an array because it makes extending it so much easier than hardcoding, for obvious reasons.
Would someone know how to adjust this code?
Thank you,
Sincerely,
~Gw
Beta Was this translation helpful? Give feedback.
All reactions