Created
May 19, 2024 19:12
-
-
Save axelson/89f61e11273cc16fc5e1a61ba487c5cf to your computer and use it in GitHub Desktop.
Obsidian DataViewJS query
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
```dataviewjs | |
function countWords(str) { | |
return str.trim().split(/\s+/).length; | |
} | |
// Replace TAG with whatever tag you wish. | |
const pages = dv.pages('#structure-note and -#meta') | |
const rows = [] | |
for (const page of pages) { | |
const file = app.vault.getAbstractFileByPath(page.file.path); | |
//get file path as string | |
var checkMe = "" + page.file.path; | |
// Read the file contents | |
const contents = await app.vault.read(file); | |
rows.push([countWords(contents), page.file.link]); | |
} | |
const sortedRows = rows.sort((a, b) => { | |
return b[0] - a[0]; | |
}); | |
dv.table(['Word Count', 'Link'], sortedRows); | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment