Skip to content

feat: add {{projectFolder}} folder template variable#2105

Open
carypruitt wants to merge 1 commit into
callumalpass:mainfrom
carypruitt:feat/project-folder-template
Open

feat: add {{projectFolder}} folder template variable#2105
carypruitt wants to merge 1 commit into
callumalpass:mainfrom
carypruitt:feat/project-folder-template

Conversation

@carypruitt

Copy link
Copy Markdown

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 in Areas/EFC/EFC/ rather than Areas/EFC/.

{{projectFolder}} covers the general case.

Project link {{projectFilePath}} {{projectFolder}}
[[Areas/EFC/EFC]] Areas/EFC/EFC Areas/EFC
[[EFC]] (root) EFC `` (empty)

With {{projectFolder}} as the Default tasks folder, a task added to project [[Areas/EFC/EFC]] is created in Areas/EFC/, next to the note.

Implementation

  • New getProjectFolder helper in src/utils/folderTemplateProcessor.ts, built on the existing getProjectFilePath so 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.
  • Two .replace calls added to processFolderTemplate, following the existing {{projectFilePath}} / {{projectFilePaths}} pattern.
  • Docstring, docs/features/template-variables.md, and docs/settings/task-defaults.md updated.

Tests

Added a {{projectFolder}} and {{projectFolders}} block to tests/unit/utils/folderTemplateProcessor.test.ts covering 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 under TZ=UTC and is untouched by this change.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant