Templater
Templater copied to clipboard
#684 - Remove 'file.stat.size == 0' from line 394
This line of code means that new files created with the DataBase Folder Plugin do not trigger Templater. Lots of people are trying to use DataBase Folder and Templater together so this pull removes the file size check which enables Templater to trigger.
Related to issue #684
Removing this line will mean that Templater will trigger when files get moved into a new folder. This will have some dangerous consequences.
Can we listen precisely for new file events instead or do file moves also trigger that?
A file move will always trigger that; even if it's something we tweaked at the API-level, you could just as easily move a file from your operating system's file system and obsidian won't be able to tell if it's a newly created file or a file that was moved into the vault.
I know I'm asking a lot here but do you see any reasonable trade-off here? I don't really have the depth to figure out the right approach here. If you can't, I'll try and block some time to investigate this.
So, a few options off the top of my head.
-
The DataBase Folder Plugin could just check if templater is installed, and if it is, directly trigger a command to apply templates based on the file location. This is the easiest IMO but maybe not the most kosher.
-
The Templater plugin could introduce a new event on the app workspace (for example:
new-markdown-file-created
and the DataBase Folder Plugin could callworkspace.trigger('new-markdown-file-created')
after it creates a new file. This would be roughly equivalent to option 1. but slightly more robust since it doesn't require checking if another plugin is installed. -
(worst option, don't do this.) DataBase Folder Plugin can create an empty file, wait some amount of time for templater to modify it, then it can add the frontmatter afterwards.
Some other random ideas that I don't think are very viable but jotting down for completeness.
- Some frontmatter flag that db folder plugin can include to mark the file as ready to be processed to templater. This could easily lead to misuse or bugs so don't do this either.
- Checking the ctime to see if the file is new vs moved. This will lead to issues if the file was moved via a cloud syncing solution or if the ctime ever got reset programmatically
There are definitely better approaches and I'll give it some thought for how this can be solved from Obsidian's side. Templater's Folder Templates are pretty dangerous IMO and I think we can offer something better if it's baked into the core app.
Closing based on the conversation above.