Hello, I am trying to setup a `org-roam-capture-new-node-hook`, that will add a property to a daily/journal file automatically. while skipping other types of notes.
here's the function I have
(defun my/org-roam-dailies--daily-note-p (file)
"Return t if FILE is an Org-roam daily-note, nil otherwise.
If FILE is not specified, use the current buffer's file-path."
(when-let ((path (expand-file-name file))
(directory (expand-file-name org-roam-dailies-directory org-roam-directory)))
(setq path (expand-file-name path))
(f-descendant-of-p path directory)))
When I call this normally, I get expected response.
(when (my/org-roam-dailies--daily-note-p "/path/to/org/roam/daily/2022-01-26.org")
"Cool")
: Cool
But when I call this from the custom hook function,
(defun my/add-auto-props-to-org-roam-dailies ()
"Add properties to org-roam daily entry automatically"
(unless (file-exists-p (buffer-file-name))
(when (my/org-roam-dailies--daily-note-p (buffer-file-name))
(unless (org-find-property "header-args:ledger")
(org-roam-add-property
(concat
(file-name-as-directory (ledger-path-relative-to-org))
(file-name-base (buffer-file-name)) ".ledger")
"header-args:ledger")
(org-roam-add-property ":tangle" "header-args:ledger")))))
(add-hook! 'org-roam-capture-new-node-hook #'my/add-auto-props-to-org-roam-dailies)
This does not seem to work as expected. The call to `my/org-roam-dailies--daily-note-p` seem to return nil for all files. Am I missing something here?
if I remove the check (call for `my/org-roam-dailies--daily-note-p`), the property gets added correctly for all files, so rest of the code is working as intended.
P.S. `ledger-path-relative-to-org` is a custom function that returns a relative path to where I expect the ledger files to get tangled.