Templater icon indicating copy to clipboard operation
Templater copied to clipboard

#684 - Remove 'file.stat.size == 0' from line 394

Open ObsidianTTRPGProject opened this issue 2 years ago • 5 comments

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

ObsidianTTRPGProject avatar Aug 03 '22 12:08 ObsidianTTRPGProject

Removing this line will mean that Templater will trigger when files get moved into a new folder. This will have some dangerous consequences.

liamcain avatar Aug 03 '22 17:08 liamcain

Can we listen precisely for new file events instead or do file moves also trigger that?

AB1908 avatar Aug 03 '22 19:08 AB1908

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.

liamcain avatar Aug 03 '22 21:08 liamcain

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.

AB1908 avatar Aug 03 '22 22:08 AB1908

So, a few options off the top of my head.

  1. 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.

  2. The Templater plugin could introduce a new event on the app workspace (for example: new-markdown-file-created and the DataBase Folder Plugin could call workspace.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.

  3. (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.

liamcain avatar Aug 04 '22 01:08 liamcain

Closing based on the conversation above.

shabegom avatar Sep 01 '22 13:09 shabegom