If you really want to sort by word count, and you have Better Word Count installed, you can use its new API within a dataviewjs code block.
When this came out, I implemented a table that relies on this API to get an overview of the word counts and writing progress for the notes that are part of my master’s thesis:
I adapted that script for your usecase below. It displays a table with the top 10 files (word-count-wise), sorted by word count. It also shows how many days ago you last modified each note. I limited the query to files with the “md” extension. Since this includes Excalidraw files, I made a separate check for that, to filter them out.
```dataviewjs
const bwc = app.plugins.plugins["better-word-count"].api;
const luxon = dv.luxon;
// Get all pages in the vault
const pages = await dv.pages('""').where(page => page.file.ext === "md" && page.file.path.endsWith("excalidraw.md") == false);
// Array to store the final rows for the table
const tableRows = [];
// Use Promise.all to wait for all word counts
await Promise.all(pages.map(async (page) => {
const wordCount = await bwc.getWordCountPagePath(page.file.path);
page.wordCount = wordCount;
}));
// Create a new array that is sorted
const sortedPages = [...pages].sort((pageA, pageB) => pageB.wordCount - pageA.wordCount);
// Iterate through the sorted pages and add rows to the tableRows array
const numberOfNotesToShow = 10; // Number of largest notes to display
for (let i = 0; i < numberOfNotesToShow && i < sortedPages.length; i++) {
const page = sortedPages[i];
const wordCount = page.wordCount;
const relativeModified = luxon.DateTime.fromISO(page.file.mtime).toRelative();
tableRows.push([
page.file.link,
wordCount,
relativeModified,
]);
}
// Print the table with the top notes based on word count
dv.table(["Name", "Word Count", "Last modified"], tableRows);
```
If you want to use it, I recommend limiting the query to a particular folder, like your inbox folder, to make it run faster. When run on your whole vault, it can take a while to load (maybe 5 seconds?).