Skip to content

Instantly share code, notes, and snippets.

@eleanorkonik
Created February 17, 2022 15:46
Show Gist options
  • Save eleanorkonik/c650c193751436463f427690f680546e to your computer and use it in GitHub Desktop.
Save eleanorkonik/c650c193751436463f427690f680546e to your computer and use it in GitHub Desktop.
```dataviewjs
//get all md files in vault
const files = app.vault.getMarkdownFiles()
//create an array with the filename and lines that include the desired tag
let arr = files.map(async(file) => {
const content = await app.vault.cachedRead(file)
//turn all the content into an array
let lines = await content.split("\n").filter(line => line.includes("- [?]"))
return ["[["+file.name.split(".")[0]+"]]", lines]
})
//resolve the promises and build the table
Promise.all(arr).then(values => {
console.log(values)
//filter out files without "ad-question" and the note with the dataview script
const exists = values.filter(value => value[1][0] && value[0] != "[[dataviewjs-testing]]")
dv.table(["file", "lines"], exists)
})
```
@JWolfcat
Copy link

JWolfcat commented Feb 23, 2023

1st of all thanks for this
I've being searching for this a long time, and it lead me to this:

TASK
WHERE contains(status, "?")
GROUP BY file.link

This can make the same as yours (Showing only the ?, i, *....) but easily you can filter by file, which I prefer, because I use this in a specific section of my vault and I dont want it to show every "alternative task" in the vault, but an specific #.
It would be like this:

TASK
FROM #YourChoice
WHERE contains(status, "?")

And if you want a list of all alternative tasks together

TASK
WHERE checked AND !completed
SORT file.name DESC

And I love this because I don't know js, and this just uses the dataview syntax which is really easy to remember..
This could be old news for you, but for me is a long time goal achieved.

Thanks again, without yours I wouldn't had ever start looking for this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment