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 }}
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)
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.
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:
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
{{ range $backlinks }}- <a href="{{ .
https://seds.nl/notes/export_org_roam_backlinks_with_gohugo/
Thank you so much for this. Works like a charm :)
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)
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!
@sjgknight Glad you got it fixed!
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: