Hi, I’ve asked about this in the Discord, and got something that’s half there. But not quite. So I’ll try here.
What I want to achieve
I want to list people born in a country/city/state on the note of this state, using data view
What I have
I have a file for each day of the year, in ISO date format. So April 19, is “04-19” and so on. On each of the notes, I have bullet lists of things that happened on that date. Usually things from Wikipedia and other sources, but also all my own stuff. I do use daily notes, but I also tag all notes to the date WITHOUT the year.
So if I make a note today (“2021-07-09”) I also link it to “07-09”. That way, next year, I can see what I did/made on this date.
People born
I use bullet points to add facts on the day of the year notes. So today, “07-09”, it could look like this:
• 1819 Elias Howe, inventor of sewing machine, #born in Spencer, Massachusetts.
• 1957 Marc Almond, singer, #born in Southport, Lancashire, England
• 1959 Jim Kerr , singer, #born i Glasgow, Scotland
I do this for other events too, so #born is just an example.
Now for the problem
On the note for Scotland, I want to have a proper listing for “People born in Scotland”. If I just use dataview, I only get the note name, which for this would be “07-09”, and not “Jim Kerr”.
So I guess I need dataviewjs, which is where my skills in code start to fail.
I got this suggestion:
//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("#born"))
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 "Happy" and the note with the dataview script
const exists = values.filter(value => value[1][0] && value[0] != "[[dataviewjs-testing]]")
dv.table(["file", "lines"], exists)
})
NB: You need to add the ``` in front and after to test it in Obsidian.
Half way there
This lists all the lines with #born on them. But it’s listed by document, not sorted by year, and it doesn’t search for places/city names.
So any help, is appreciated. I’m oyvind on twitter if you want to send me DMs.