I drafted this as a help request – then revisited the problem before posting it and figured it out.
Sharing the solution, as I’m pretty pleased with Base formulas can do!
What I’m trying to do
I have a very simple project & task structure.
Project files live in folders with paths like:
Projects/Torment_Nexus
Project “home” notes are Folder Notes auto-named after the parent folder:
Projects/Torment_Nexus/Torment_Nexus.md
A central task base lists any active notes in project folders throughout the vault. I’d like the entries to include links to their project home pages – the Folder Notes.
Things I have tried
The formula Link(file.folder) comes close, but it doesn’t know about Folder Notes. The result is a link to a non-existent note at:
Projects/Torment_Nexus.md
So…
I know I could put a link in a “Project” property for every note – but I’d like to just leverage the consistent folder structure I already have.
Is there any way to build a formula that will link to the relevant parent Folder Note?
Answer: yes!
After some experimenting with the functions split and slice:
link(
file.folder + "/" +
file.folder.split("/").slice(-1) + ".md",
file.folder.split("/").slice(-1)
)
This formula builds a link in this order:
file.folder + "/" +
- Get the
file.folder(“Projects/Torment_Nexus”) - Append a
/character so it’s ready for the filename (“Projects/Torment_Nexus/_________”)
file.folder.split("/").slice(-1) + ".md",
splitthe original folder path by the pre-existing “/” to get parts:["Projects", "Torment_Nexus"]- Use
slice(-1)to back up one step from the end and extract the folder as the project name (“Torment_Nexus”) - Append
.mdto that element to make the Folder Note filename (“Torment_Nexus.md”) - Combine it all to form the full path to the Folder Note: “/Projects/Torment_Nexus/Torment_Nexus.md”
file.folder.split("/").slice(-1)
- After the comma in the formula, split & grab the project name element (“Torment_Nexus”) again as a second ‘display’ parameter for the link, so we don’t have to see the full path.
The result is the link:
[Torment_Nexus](Projects/Torment_Nexus/Torment_Nexus.md)
Perfect. Thanks, me! Maybe this’ll help someone else too.
(tasks.base code view)
filters:
and:
- '!file.name.startsWith("Project")'
formulas:
folder link: |-
link(file.folder + "/" + file.folder.split("/").slice(-1) + ".md", file.folder.split("/").slice(-1)
)
views:
- type: table
name: active
filters:
and:
- status.containsAny("next", "active")
- formula["folder link"].startsWith("Project")
order:
- file.name
- status
- formula.folder link
sort:
- property: formula.folder link
direction: ASC
- property: date created
direction: DESC
