Based on this (I can’t post links, sorry):
- Dataview query to extract a list item and all its sublist items
- Include children (sub-list items) in query for list times with a tag
- Retrieve list of bullet points and their sub-sub-items
And this:
- icewind.quest/characters/arcane-brotherhood/vellynne-harpell/
What I’m trying to do
I’m interested in:
- quering all notes and their lists in a specific folder
- pulling the lines that contain this.file.link
- pulling their children
- grouping results by item.link (/folder/file_name/#slosest_heading)
The goal is basically the same as icewind.quest’s character pages - aggregating and displaying all encounters with said character on a single page.
However, icewind.quest’s solution requires marking every line with these kinds of contraptions (x:: ), which is a nightmare for me to compose. Also, it only pulls in single paragraphs, and it’s not really readable - you don’t always want to keep everything in a single slab of text.
So, for myself I’ve decided that it would be best to try to format it as a list.
Things I have tried
I want to apologize in advance for the horrors that you may encounter below in the code. I don’t really know what I’m doing - blindly poking around, trying to make something that works. It’s too much, and I’m asking for help.
Dataview LIST with grouping
First, I’ve cobbled together this:
LIST
regexreplace(
replace(
rows.item.text,
"[[" + this.file.name + "]]",
this.file.name
),
"\[\[" + this.file.name + "\|(.+?)\]\]",
"$1"
)
FROM "Journal"
FLATTEN file.lists AS item
WHERE contains(item.text, this.file.name)
SORT file.name desc
GROUP BY item.link
The regex part cleans up the redundant links that loop back to this.file.name while trying to keep link aliases where they’re present - pay no attention to that part.
It produces a readable result that I sort of like, which (most importantly) works with Digital Garden.
It looks something like this (in the browser it renders as a clean bullet list with tags and links):
- [[03. After the Siege > Evening at the manor]]: (this is the item.link, which links to the session_file#closest_heading)
-- [[NPC1]] tried to steal our cakes and hotdogs
- [[03. After the Siege > Morning]]:
-- #Quest01 [[NPC1]] met us at the Tavern
-- [[NPC1]] sought us out again and spoke of [[NPC3]] and an [[Important artifact]] once more.
- [[04. City at night > At the tavern]]:
-- He said that [[NPC1]] stole his cakes as well
- [[04. City at night > Shaded streets]]:
-- #Quest02 [[NPC1|The same guy]] tried to follow us in the dark
-- #Quest02 [[NPC1|The cake and hotdog bandit]] suddenly appeared before us, holding a new batch of cakes
-- [[NPC1]] got scared and ran off, dropping the cakes along the way
The good
- It works in Digital Garden flawlessly - nothing is broken
- There is grouping by file/heading - which is very convenient - you can easily jump to sections that contain these matches
The bad
- It returns only direct matches - there are no child elements which makes this approach mostly useless for me (while you can hover over the heading link on desktop and preview it - to see if there’s something more, on mobile you cannot)
- The files are in the right order, but the headings are reversed (Evening before Moning, for example) - tinkering with SORT did nothing
Modified holroy’s function
This is the closest I’ve got to the result I want.
I’ve tried to modify the holroy’s code to work for my case (see link above).
const dvF = dv.evaluationContext.functions
// Create a new DQL function
dvF.listChildren = (ctx, children, offset = "" ) => {
let result = ""
for (const child of children) {
result += offset + "- " +
child.text + "\n"
if (child.children.length)
result += dvF.listChildren(ctx, child.children, offset + " ")
}
return result
}
const result = await dv.query(`
LIST WITHOUT ID
item.link + "\n" + item.text + "\n" + listChildren(item.children)
FROM "Journal"
FLATTEN file.lists as item
WHERE !item.parent AND contains(item.text, this.file.name)
`)
if ( !result.successful ) {
dv.paragraph("~~~~\n" + result.error + "\n~~~~")
return
}
dv.list(result.value.values)
// Cleanup after our new function
delete dvF.listChildren
The good
It returns child elements!
The bad
There is no grouping
Things that should look like this:
- [[file_heading1]]
-- match1
-- match2
Look like this:
- [[file_heading1]]\n match1
- [[file_heading1]]\n match2
It doesn’t handle cases such as this:
- [[file_heading]]
-- NOT a match
--- NOT a match
---- match
Removing the WHERE !item.parent handles these, but produces unwanted results.
And the worst thing
When publishing to Digital Garden, all links contained in lines produced by listChildren(item.children) are broken (data-href can say “Tavern” while href will say “404”). Links that are produced by LIST item.link are fine. Inside Obsidian itself, all links are working.
I’ve also tried AI, but it’s a total mess - I won’t be posting that here…
Is it too complex? Should I stick to basic list?