feat(buttons): Add date format placeholders for templaterCreateNote and createNote actions#643
feat(buttons): Add date format placeholders for templaterCreateNote and createNote actions#643hsayed21 wants to merge 3 commits intomProjectsCode:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for dynamic date format placeholders in the fileName and folderPath properties of button actions, enabling users to create date-based file names and organize notes by date automatically using moment.js format tokens wrapped in curly braces (e.g., {YYYY-MM-DD}).
Key Changes:
- Implements date placeholder processing using regex pattern
/\{([^}]+)\}/gto detect and replace format tokens - Processes both
fileNameandfolderPathbefore file operations - Applies the same functionality to both
createNoteandtemplaterCreateNotebutton actions
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| packages/core/src/fields/button/actions/TemplaterCreateNoteButtonActionConfig.ts | Adds processDateFormatPlaceholders method and applies date processing to fileName and folderPath before creating notes with Templater |
| packages/core/src/fields/button/actions/CreateNoteButtonActionConfig.ts | Adds processDateFormatPlaceholders method and applies date processing to fileName and folderPath before creating notes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/core/src/fields/button/actions/TemplaterCreateNoteButtonActionConfig.ts
Outdated
Show resolved
Hide resolved
packages/core/src/fields/button/actions/CreateNoteButtonActionConfig.ts
Outdated
Show resolved
Hide resolved
packages/core/src/fields/button/actions/CreateNoteButtonActionConfig.ts
Outdated
Show resolved
Hide resolved
packages/core/src/fields/button/actions/CreateNoteButtonActionConfig.ts
Outdated
Show resolved
Hide resolved
packages/core/src/fields/button/actions/TemplaterCreateNoteButtonActionConfig.ts
Outdated
Show resolved
Hide resolved
packages/core/src/fields/button/actions/TemplaterCreateNoteButtonActionConfig.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/core/src/fields/button/actions/CreateNoteButtonActionConfig.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
packages/core/src/utils/Utils.ts:391
- Character 's' is repeated in the same character class.
const validMomentFormat = /^[YMDdHhmsaAQWwXxZzGgEeSsokl:/\-\s.,[\]]+$/.test(format);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const processedFileName = processDateFormatPlaceholders(action.fileName); | ||
| const processedFolderPath = processDateFormatPlaceholders(action.folderPath); | ||
|
|
||
| if (action.openIfAlreadyExists && action.fileName) { |
There was a problem hiding this comment.
The condition checks action.fileName instead of processedFileName. If date placeholder processing results in an empty string or the original action.fileName is just a placeholder that becomes empty, the openIfAlreadyExists logic may not work as intended. Consider checking processedFileName instead, or ensure the processed value is truthy before attempting to open the existing file.
| const processedFileName = processDateFormatPlaceholders(action.fileName); | ||
| const processedFolderPath = processDateFormatPlaceholders(action.folderPath); | ||
|
|
||
| if (action.openIfAlreadyExists && action.fileName) { |
There was a problem hiding this comment.
The condition checks action.fileName instead of processedFileName. If date placeholder processing results in an empty string or the original action.fileName is just a placeholder that becomes empty, the openIfAlreadyExists logic may not work as intended. Consider checking processedFileName instead, or ensure the processed value is truthy before attempting to open the existing file.
| // Validate that the format string only contains valid moment.js tokens and delimiters | ||
| // Moment.js tokens: Y M D d H h m s S a A Q W w X x Z z G g E e o k l | ||
| // Common delimiters: : / - space . , [ ] | ||
| const validMomentFormat = /^[YMDdHhmsaAQWwXxZzGgEeSsokl:/\-\s.,[\]]+$/.test(format); |
There was a problem hiding this comment.
The regex character class contains 'S' twice: once standalone and once in 'Ss'. While this doesn't break functionality (duplicate characters in character classes are simply ignored), it's redundant and could indicate a typo or oversight. Consider simplifying the pattern to remove the duplication.
| action.folderPath ?? '', | ||
| action.fileName, | ||
| processedFolderPath ?? '', | ||
| processedFileName ?? 'Untitled', |
There was a problem hiding this comment.
If processedFileName is an empty string (which can happen if action.fileName is an empty string), the nullish coalescing operator won't trigger and an empty string will be passed to mb.file.create(). Consider using a falsy check instead: processedFileName || 'Untitled' to handle empty strings properly.
Summary
This PR adds support for dynamic date format placeholders in
fileNameandfolderPathproperties for bothtemplaterCreateNoteandcreateNotebutton actions. Users can now use moment.js format tokens wrapped in curly braces{format}to automatically generate date-based file names and folder paths.Motivation
Users often need to create daily notes or organize notes by date with automated buttons. Previously, they had to use static file names or complex workarounds. This feature enables seamless date-based note organization directly from Meta Bind buttons.
Real-world Use Case
Creating daily journal entries with automatic date-based naming and folder organization:
This creates notes at paths like:
001 Journal/2025/12/2025-12-18.md