Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
markup/org: add custom org link resolve function for denote
The go-org library used by hugo to parse `.org` files now supports custom link
resolvers. This PR uses the new functionality to add support for
[denote](https://protesilaos.com/emacs/denote) style links.

This can be used to publish note libraries as-is using hugo.

I've written about the details in a blog post
[here](https://dominik.suess.wtf/posts/2025/01/02/denote-hugo/).

I don't know if this functionality is too specific to my usecase so I'm happy to
discuss alternatives which could be more modular/adaptable to other systems.
  • Loading branch information
theSuess committed Jul 22, 2025
commit 13fccf202642cecc09bcd56cfdc924990787d13a
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ require (
github.com/mattn/go-isatty v0.0.20
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c
github.com/muesli/smartcrop v0.3.0
github.com/niklasfasching/go-org v1.8.0
github.com/niklasfasching/go-org v1.9.1
github.com/olekukonko/tablewriter v1.0.8
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
github.com/pelletier/go-toml/v2 v2.2.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ github.com/niklasfasching/go-org v1.8.0 h1:WyGLaajLLp8JbQzkmapZ1y0MOzKuKV47HkZRl
github.com/niklasfasching/go-org v1.8.0/go.mod h1:e2A9zJs7cdONrEGs3gvxCcaAEpwwPNPG7csDpXckMNg=
github.com/niklasfasching/go-org v1.9.0 h1:4/Sr68Qx06hjC9MVDB/4etGP67JionLHGscLMOClpnk=
github.com/niklasfasching/go-org v1.9.0/go.mod h1:ZAGFFkWvUQcpazmi/8nHqwvARpr1xpb+Es67oUGX/48=
github.com/niklasfasching/go-org v1.9.1 h1:/3s4uTPOF06pImGa2Yvlp24yKXZoTYM+nsIlMzfpg/0=
github.com/niklasfasching/go-org v1.9.1/go.mod h1:ZAGFFkWvUQcpazmi/8nHqwvARpr1xpb+Es67oUGX/48=
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 h1:G7ERwszslrBzRxj//JalHPu/3yz+De2J+4aLtSRlHiY=
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037/go.mod h1:2bpvgLBZEtENV5scfDFEtB/5+1M4hkQhDQrccEJ/qGw=
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 h1:bQx3WeLcUWy+RletIKwUIt4x3t8n2SxavmoclizMb8c=
Expand Down
14 changes: 14 additions & 0 deletions markup/org/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package org
import (
"bytes"
"log"
"strings"

"github.com/gohugoio/hugo/identity"

Expand Down Expand Up @@ -51,6 +52,19 @@ func (c *orgConverter) Convert(ctx converter.RenderContext) (converter.ResultRen
config.ReadFile = func(filename string) ([]byte, error) {
return afero.ReadFile(c.cfg.ContentFs, filename)
}
config.ResolveLink = func(protocol string, description []org.Node, link string) org.Node {
out := org.RegularLink{
Protocol: protocol,
Description: description,
URL: link,
AutoLink: false,
}
if protocol == "denote" {
id := strings.TrimPrefix(link, "denote:")
out.URL = "../" + strings.ToLower(id) + "/"
}
return out
}
writer := org.NewHTMLWriter()
writer.HighlightCodeBlock = func(source, lang string, inline bool, params map[string]string) string {
highlightedSource, err := c.cfg.Highlight(source, lang, "")
Expand Down
Loading