-
-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(summary)!: fix norg links, use first heading as title if found #928
Conversation
Hell yeah. About the workspace root - you can opt for the |
Sorry if you see a million "starting review" notifications i'm playing around with how octo.nvim does things :p |
heading_query = neorg.utils.ts_parse_query("norg", heading_query_string) | ||
end | ||
-- search up to 20 lines (a doc could potentially have metadata without metadata.title) | ||
for _, heading in heading_query:iter_captures(document_root, bufnr, 1, 20) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check between lines 1
and 20
is alright, but I think we might be better off altogether by just checking for the first occurrence in the file? I can imagine some niche scenarios where you have a long introductory paragraph to a document and only then do you have the title in a first level heading >20 lines down.
If you agree this is the way to go then the simplest way is to ditch the for
loop altogether and invoke the function manually to get the first result like this:
for _, heading in heading_query:iter_captures(document_root, bufnr, 1, 20) do | |
local _, heading = heading_query:iter_captures(document_root, bufnr)() | |
if not heading then | |
-- do something | |
end | |
-- continue using the `heading` node normally |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done - thanks for the tip, I didn't know about using (..)()
to iterate over the first item only.
Resolved a conflict w.r.t the latest |
Done, ta |
Just tested and all seems to work great. Thanks a lot for the contributions! |
Fixes and improvements following on from #927 . I noticed a bug in the link destinations, so I went ahead and did some of what @vhyrro suggested.
{:index.norg:}[My Index]
=>{:index:}[My Index]
) - lol, funny I didn't notice this last time.{:index:}
rather than{:/Users/me/notes/work/index:}
. (It assumes you're in the workspace root, which seems OK?)metadata.title
, it queries TS to find the first heading text. The TS query allows heading1 or heading2, and it checks matches up to 20 lines into the doc (e.g. if there's metadata but no title). IDK if this is right or if the query could be improved, but it seems like an OK starting point.Index
rather thanIndex.norg
.metadata
todefault
because now it uses a mixture of metadata and headings/filenames now.My summary looks like this now (as before, I only have scraps of document metadata, and some files are completely empty):