Skip to content
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

notes/export_org_roam_backlinks_with_gohugo/ #8

Open
utterances-bot opened this issue May 2, 2021 · 4 comments
Open

notes/export_org_roam_backlinks_with_gohugo/ #8

utterances-bot opened this issue May 2, 2021 · 4 comments
Labels
comment Post comment

Comments

@utterances-bot
Copy link

Export org-roam backlinks with Gohugo | Ben Mezger

tags Org-mode Emacs Org-roam Since Org-roam export backlinks on Hugo no longer works, I found a solution to handle backlinks in Hugo itself.
The following Hugo partial template will add backlinks to a note if any.
{{ $re := $.File.BaseFileName }} {{ $backlinks := slice }} {{ range .Site.AllPages }} {{ if and (findRE $re .RawContent) (not (eq $re .File.BaseFileName)) }} {{ $backlinks = $backlinks | append . }} {{ end }} {{ end }}


{{ if gt (len $backlinks) 0 }}

Links to this note

Copy link

tdehaeze commented May 2, 2021

Thank you so much for this. Works like a charm :)

Copy link

Thanks for sharing this! I've been playing with getting it working on the wowchemy research group starter (as very much not a go person...). Although the heading comes up, I don't have any links showing (although shortcode relref links are present). I do get an ".File.BaseFileName on zero object. Wrap it in if or with: {{ with .File }}{{ .BaseFileName }}{{ end }}" error but I'm not sure that's relevant. Any chance you have any tips? (repo is at https://github.com/sjgknight/starter-hugo-research-group the 2 published posts have cross-links)

Copy link

sjgknight commented Aug 8, 2021

Ah! Dumb error. If anyone is using the default wowchemy structure with a directory per-content item with index.md and whatever else in it, then obviously the filename isn't going to help much. Changing instances of BaseFileName to ContentBaseName fixes that easily enough.

It does look for case matching (I guess in the original too). I think this can be fixed with 'lower' but I don't understand go scopes enough.

Thanks!

@benmezger
Copy link
Owner

benmezger commented Aug 8, 2021

Ah! Dumb error. If anyone is using the default wowchemy structure with a directory per-content item with index.md and whatever else in it, then obviously the filename isn't going to help much. Changing instances of BaseFileName to ContentBaseName fixes that easily enough.

@sjgknight Glad you got it fixed!

It does look for case matching (I guess in the original too). I think this can be fixed with 'lower' but I don't understand go scopes enough.

Maybe you can try something like this: {{ lower .ContentBaseName }} . See: https://gohugo.io/functions/lower/
In case you need to check my source code further, it is available here:

@benmezger benmezger added the comment Post comment label Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comment Post comment
Projects
None yet
Development

No branches or pull requests

4 participants