I want to extract all level one headlines of notes as a title. My plan is to have that only for daily notes, because I use them for meeting notes, where the level one headline names the meeting. For all other notes, the “normal” title extraction is fine. But as a first try, I just try to add for all notes:
I would put a break point with using edebug-defun on the org-roam--extract-titles function and see how your user option behaves in the actual runtime step-by-step.
If this was not something you would opt to do, then I would need to ask someone more knowledgeable to advise.
recently, I have migrated to roam v2, which worked flawless for me. However, it seems that the customization of title extraction is not available anymore. There is no mention of it in Org-roam User Manual and the variable org-roam-title-sources seems to be gone.
Is that correct? If yes, is there a workaround or a plan when to re-introduce this feature?
Not exactly what I am looking for. I think it might not really be possible anymore with v2, as now anything with an id is considered a headline, regardless of where it is located.
Quoting an older version of the manual from Org-roam User Manual (link to wayback machine)
To control how Org-roam extracts titles, customize org-roam-title-sources. If all methods of title extraction return no results, the file-name is used as the note’s title.
User Option: org-roam-title-sources
The list of sources from which to retrieve a note title. Each element in the list is either:
a symbol – this symbol corresponds to a title retrieval function, which returns the list of titles for the current buffer
a list of symbols – symbols in the list are treated as with (1). The return value of this list is the first symbol in the list returning a non-nil value.
The return results of the root list are concatenated.
For example the setting: ’((title headline) alias) means the following:
Return the ’title + ’alias, if the title of current buffer is non-empty; Or return ’headline + ’alias otherwise.
[…]
Adding your own title extraction method requires two steps. First, define a method (defun org-roam--extract-titles-foo () ...), where foo a self-prescribed name for the title extraction method. This method takes no arguments, and returns a list of strings (titles). Finally, push the symbol foo into org-roam-title-sources. You may need to rebuild the cache from scratch to re-process all files to pick up the new titles.
So basically, it controls how to get a list of notes (which you can select using org-roam-find-note from a file.
First, look for the note’s title; if not found, look for the first headline (find title or headline)
Second, look for aliases
You can also define your own function and use it.
Then… I agree with @doubleloop, and find his suggestion spot on.
What do you think is missing?
If you look at the docstring of org-roam-node-display-template, you get the following.
I agree that extracting the first headline when the title is not found may not make sense (although, you could do it if you code a new method). This new convention gives you the same level of freedom – I think it’s easier to use.
The wiki @doubleloop points to above contains collection of different methods that the community has come up with.
You might want to give a try and see if you can replicate what you use to do with the V1 method.
Each "field-name" is replaced with the return value of each
corresponding accessor function for ‘org-roam-node’, e.g.
"${title}" will be interpolated by the result of
‘org-roam-node-title’. You can also define custom accessors using
‘cl-defmethod’. For example, you can define:
(cl-defmethod org-roam-node-my-title ((node org-roam-node))
(concat "My " (org-roam-node-title node)))
and then reference it here or in the capture templates as
"${my-title}".
Sorry, just read the whole thread; so this is what you wanted to achieve all along?
Would you still want to do this ? I missed the context completely. Apologies.
But you should be able to do it. Node contains the path/filename, so from there you can get the first headline.
EDIT: I put this together below. I did a casual testing and ti works. But… I think it’s better to change the DB update (replace the value of title) for performance. The first-heading-or-title method gets executed for every candidate when you call org-roam-node-find. Not the best approach if you have a large number of nodes.