await dv.view("__annex__/resources/obsidian/plugins/dataview/views/noteweights.dataview", {includePaths: ["knowledge"]})
Created
April 30, 2023 08:17
-
-
Save jeetsukumaran/784a3ea62a0cb83f02ecefe9de427999 to your computer and use it in GitHub Desktop.
"Lightning rods of thought using Dataview" -- Filter paths in links as well
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function runQuery(options) { | |
options = options || {} | |
// const excludePatterns = options.excludePatterns ?? [] | |
// const includePatterns = options.includePatterns ?? [] | |
const excludePaths = options.excludePaths ?? [] | |
const includePaths = options.includePaths ?? [] | |
const limit = options.limit ?? 50 | |
const allPages = dv.pages() | |
let sourcePages = null | |
if (includePaths.length) { | |
for (let pathStr of includePaths) { | |
let filteredPages = allPages | |
.where(p => p.file.path.contains(pathStr)) | |
.mutate(p => p.file.inlinks = p.file.inlinks.filter(link => link.path.contains(pathStr))) | |
.mutate(p => p.file.outlinks = p.file.outlinks.filter(link => link.path.contains(pathStr))) | |
if (filteredPages) { | |
if (sourcePages) { | |
sourcePages = sourcePages.concat(filteredPages) | |
} else { | |
sourcePages = filteredPages | |
} | |
} | |
} | |
} else { | |
sourcePages = allPages | |
} | |
for (let pathStr of excludePaths) { | |
sourcePages = sourcePages.where(p => !p.file.path.contains(pathStr)) | |
.mutate(p => p.file.inlinks = p.file.inlinks.filter(link => link.path.contains(pathStr))) | |
.mutate(p => p.file.outlinks = p.file.outlinks.filter(link => link.path.contains(pathStr))) | |
} | |
if (options.sort == "inlinks") { | |
sourcePages = sourcePages.sort(p => p.file.inlinks.length, options.sortDir ?? "desc") | |
} else { | |
sourcePages = sourcePages.sort(p => p.file.outlinks.length, options.sortDir ?? "desc") | |
} | |
if (limit) { | |
sourcePages = sourcePages.limit(limit) | |
} | |
dv.table( | |
[ | |
"Note", | |
"Inlinks", | |
"Outlinks", | |
], | |
sourcePages.map(p => [ | |
p.file.link, | |
p.file.inlinks.length, | |
p.file.outlinks.length, | |
] ) | |
) | |
} | |
runQuery(input) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment