neorg-templates icon indicating copy to clipboard operation
neorg-templates copied to clipboard

bug(builtin-snippets): OF_FILENAME and OF_FILETREE do the same thing

Open OddDev opened this issue 10 months ago • 1 comments

Bug

If utilizing the builtin snippets with the "special" suffixes OF_FILENAME and OF_FILETREE, they both output the same thing.

https://files.catbox.moe/0ibzy3.mp4

Reproduce

  1. Create a new template
  2. Put in {YESTERDAY_OF_FILENAME}, {TOMORROW_OF_FILENAME}, {YESTERDAY_OF_FILETREE}, {TOMORROW_OF_FILETREE}
  3. Write the templato to a buffer
  4. The variables are replaced with the same string of format YYYY-MM-dd (https://files.catbox.moe/0ibzy3.mp4)

Template File

* Links
** {{:{YESTERDAY_OF_FILETREE}:}}[Yesterday (path)]
** {{:{YESTERDAY_OF_FILENAME}:}}[Yesterday (name)]
** {{:{TOMORROW_OF_FILETREE}:}}[Tomorrow (path)]
** {{:{TOMORROW_OF_FILENAME}:}}[Tomorrow (name)]

Expected Behavior

As described in the README:

TODAY_OF_FILENAME will insert the date by parsing the filename. OF_FILENAME is useful when journal.strategy == "flat". So, if the filename is 2023-01-01.norg, YESTERDAY_OF_FILENAME => 2022-12-31.

Similarly, TODAY_OF_FILETREE is useful when journal.strategy == "nested". Ex: if the filename is /path/to/2023/01/01.norg, YESTERDAY_OF_FILETREE => 2022-12-31.

My expectation would be, that TODAY_OF_FILETREE actually gets parsed to 1.norg for the first day in a month.

Notes

I also tried to utilize OF_FILEPATH which led to an error, as that couldn't be found. I got that from https://github.com/pysan3/dotfiles/blob/main/nvim/templates/norg/journal.norg.

I think that even the description in the README is wrong:

Similarly, TODAY_OF_FILETREE is useful when journal.strategy == "nested". Ex: if the filename is /path/to/2023/01/01.norg, YESTERDAY_OF_FILETREE => 2022-12-31.

Shouldn't that be:

Similarly, TODAY_OF_FILETREE is useful when journal.strategy == "nested". Ex: if the filename is /path/to/2023/01/01.norg, YESTERDAY_OF_FILETREE => /path/to/2022/12/31.norg.

OddDev avatar May 26 '25 08:05 OddDev

local yesterday = os.time() - 24 * 60 * 60
local blubb = "%Y" .. "/" .. "%m" .. "/" .. "%d.norg"

local output = os.date(blubb, yesterday)

That's more or less how they do it in the journal module btw. 😊

OddDev avatar May 28 '25 13:05 OddDev