Filter certain lines and file.tags at same time

What I’m trying to do

I’m totally new to dataviewjs and typescript (actually not familiar with any code at all) so this probably is a dumb question.
I’ve tried to achieve a dv.table() with certain lines in a markdown file and also with certain tags (for file tags, not the tag comes with the lines ).
for example,

|filename|lines with background color|#tags|

I’ve found this code:

const files = app.vault.getMarkdownFiles()
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("background-color: #"))
return ["[["+file.name.split(".")[0]+"]]", lines]
})
Promise.all(arr).then(values => {
console.log(values)
//filter out files without "Happy" and the note with the dataview script
const exists = values.filter(value => value[1][0] && value[0] != "[[exclude]]")
dv.table(["file", "lines"], exists)
})

I think probably I need to add some filter to files = app.vault.getMarkdownFiles() part to filter files with certain tags…
However, after 2days working I got nothing…
Any help is very very appreciated!

:sweat_smile: three days after I got no answers…
It helped a lot if anyone could tell me whether this is possible.
Please let me know what you feel for this question, thanks!

I’m not versed in code, even less in JS. So, my points are just an append to solve your question (I hope), not “the” best solution to do it, I suppose.

  • let lines = await content.split("/n").filter... - I think the “/n” is wrong. You need to use \n
  • && value[0] != "[[exclude]]" - this part is related to the exclusion of the current note (where the query is placed). Because the query search in the full content, the expression you write in your query (“background-color: #”) will count for the results. To avoid that, you need to filter out the current note. Replace “[[exclude]]” by “[[your current note title]]”
  • now, the filter the pages by a tag. Try replace const files = app.vault.getMarkdownFiles() by
const files = app.vault.getMarkdownFiles().filter(p => dv.page(p.path).file.etags.includes("#tag"))

(change the “#tag” part to your real tag)

Many thanks for you!
This really help me a lot! :laughing:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.