I have a page with multiple headers and each header has a task assigned to it, i.e.
# First thingy
- [ ] #done
The blahblah in the blahblah
# Second thingy
- [ ] #done
... etc.
I wanted to have a list of all Headers at the top of the page with the state of their task, so I made this:
asmw = asmw or {}
function asmw.headingForRef(ref)
local parts = string.split(ref, "@")
local pagepart = parts[1]
local position = tonumber(parts[2])
local headers = query[[
from index.tag "header"
where _.page == pagepart and _.pos <= position
order by pos desc
limit 1
]]
return headers[1] and headers[1].name or "[Unknown]"
end
asmw.taskHeaderItem = template.new([==[
* [${state}] [[${ref}|${asmw.headingForRef(ref)}]]
]==])
Which I can now use like this on any such page:
${template.each(query[[from index.tag "done" where page == editor.getCurrentPage()]], asmw.taskHeaderItem)}
One issue is, that toggling the task under the header does not immediately update the task in the list, the other way around it works fine.
And if anyone has hints to make the string splitting nicer, please tell me.
