benmezger / blog

Personal blog source
https://seds.nl
BSD 3-Clause "New" or "Revised" License
6 stars 3 forks source link

notes/export_org_roam_backlinks_with_gohugo/ #8

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

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

tdehaeze commented 3 years ago

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

sjgknight commented 2 years ago

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)

sjgknight commented 2 years ago

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 commented 2 years ago

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: