Skip to content

Instantly share code, notes, and snippets.

@axelson
Created May 19, 2024 19:12
Show Gist options
  • Save axelson/89f61e11273cc16fc5e1a61ba487c5cf to your computer and use it in GitHub Desktop.
Save axelson/89f61e11273cc16fc5e1a61ba487c5cf to your computer and use it in GitHub Desktop.
Obsidian DataViewJS query
```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