feat: add {{projectFolder}} folder template variable#2105
Open
carypruitt wants to merge 1 commit into
Open
Conversation
Adds {{projectFolder}} and {{projectFolders}} template variables for the
Default tasks folder / folder-path settings. Each resolves to the folder
*containing* a project note, i.e. the project file path with the note's own
basename removed.
This fills a gap between the two existing project path tokens:
- {{project}} gives the note's basename (no folder), so it only lands a task
beside its project note when the note happens to sit at the vault root in a
folder matching its name.
- {{projectFilePath}} gives the full path including the note basename, which
nests an extra folder (a task for [[Area/Proj/Proj]] lands in
Area/Proj/Proj/ rather than Area/Proj/).
{{projectFolder}} resolves to the containing folder in all cases
(Area/Proj/Proj -> Area/Proj), and to an empty string when the project note
is at the top level. This lets tasks be stored beside their project note
regardless of how deeply the note is nested.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds two folder template variables,
{{projectFolder}}and{{projectFolders}}, usable anywhere folder-path templates are processed (Default tasks folder, folder for inline-created tasks, etc.).{{projectFolder}}resolves to the folder containing the first linked project note, i.e. the project's file path with the note's own basename removed.{{projectFolders}}does the same for every linked project, joined with/.Why
There is currently no way to store a task in the same folder as its project note. The two existing project path tokens each miss:
{{project}}returns the note's basename with no folder. It only lands a task beside its project note when the note sits at the vault root in a folder matching its own name.{{projectFilePath}}returns the full path including the note basename, which nests an extra folder: a task for[[Areas/EFC/EFC]]lands inAreas/EFC/EFC/rather thanAreas/EFC/.{{projectFolder}}covers the general case.{{projectFilePath}}{{projectFolder}}[[Areas/EFC/EFC]]Areas/EFC/EFCAreas/EFC[[EFC]](root)EFCWith
{{projectFolder}}as the Default tasks folder, a task added to project[[Areas/EFC/EFC]]is created inAreas/EFC/, next to the note.Implementation
getProjectFolderhelper insrc/utils/folderTemplateProcessor.ts, built on the existinggetProjectFilePathso wikilink/markdown-link parsing and path sanitization are shared. It drops the final path segment and returns an empty string when the project note has no containing folder..replacecalls added toprocessFolderTemplate, following the existing{{projectFilePath}}/{{projectFilePaths}}pattern.docs/features/template-variables.md, anddocs/settings/task-defaults.mdupdated.Tests
Added a
{{projectFolder}} and {{projectFolders}}block totests/unit/utils/folderTemplateProcessor.test.tscovering nested notes, top-level notes (empty result), the store-beside-project-note case, multi-project joining with empties dropped, and the no-projects case. All pass.Note: one unrelated pre-existing test in this file (
issue #816 specific use case) is timezone-sensitive and fails under non-UTC local time (off by one day); it passes underTZ=UTCand is untouched by this change.