Custom markdown links stopped working

Worked in v0.64.1 and stopped working in v0.65.0. Still not working with v0.68.3
Minimal reproducible example: Github

Uses example render-link.html from bep’s demo
Edit: I use this to utilize hugo’s render hooks

With the example, I expect the [test](hello#test) in content/_index.md should resolve to /dir1/dir2/dir3/hello/#test (which it does in 64.1).
However, in 65+ it resolves to /hello#test (and shows 404)

was there a change in behavior? Or is it a bug?

we have a new markdown processor (goldmark).
The last value (hello#test) must be an URL, see here https://spec.commonmark.org/0.29/#links

You can use {{< ref "document.md" >}}
see here

Anyone can correct me, if I’am wrong.

I don’t believe it’s using the markdown processing since it should be using hugo’s render hooks (should of mentioned this more explicitly).
Testing it by modifying render-link.html showed that to be true.

This gives you full control over how links and images in Markdown are rendered without using any shortcodes.

my config has this

markup:                                                                         
  goldmark:                                                                     
    renderer:                                                                   
      unsafe: false

So I think it uses goldmark for both versions when I’m testing it.

What I’m looking to do is use the render hook to basically simulate {{< ref “document.md” >}}.
Bep’s example worked until v0.65.0 and then showed my first posts behavior.

without a sample repository … it is hard to say :roll_eyes:

this is my render-link.html

<a href="{{ .Destination | safeURL }}"  
{{ with .Title}} title="{{ . }}"{{ end }}
{{ if strings.HasPrefix .Destination "http" }} 
    target="_blank" rel="noopener noreferrer"
{{ end }} >
{{ .Text }}</a>

the example in the DOC section Configure Markup | Hugo uses a complete URL as value - so my hint

Sample from the docs: [test]({{< ref “hello.md#test” >}})

PS: It should work … see

You must use .Page.GetPage in the hook (I’m not using !) + a hint for me

[test](/dir1/dir2/dir3/hello.md/#test) should work

I added :GetPage to my hook - formatted here

<a href="{{ .Destination | safeURL }}" 
{{ with .Title}} title="{{ . }}"{{ end }}
{{ if strings.HasPrefix .Destination "http" }} 
	target="_blank" rel="noopener noreferrer"
{{else}}
	{{ with site.GetPage .Destination}} href={{.RelPermalink}} {{end}}
{{end}}>{{ .Text }}</a>

Yes, I provided one:

Minimal reproducible example: Github
With the example, I expect the [test](hello#test) in content/_index.md should resolve to /dir1/dir2/dir3/hello/#test (which it does in 64.1).
However, in 65+ it resolves to /hello#test (and shows 404)

You must use .Page.GetPage in the hook (I’m not using !) + a hint for me

My example in the sample repository does:

{{/* https://github.com/bep/portable-hugo-links/blob/master/layouts/_default/_markup/render-link.html */}}
{{- $link := .Destination -}}
{{- $isRemote := strings.HasPrefix $link “http” -}}
{{- if not $isRemote -}}
{{- $url := urls.Parse .Destination -}}
{{- if $url.Path -}}
{{- $fragment := “” -}}
{{- with $url.Fragment -}}{{- $fragment = printf “#%s” . -}}{{- end -}}
{{- with .Page.GetPage $url.Path -}}{{- $link = printf “%s%s” .RelPermalink $fragment -}}{{- end -}}{{- end -}}
{{- end -}}

[test](/dir1/dir2/dir3/hello.md/#test) should work

Yes it does, which is good.

In links and cross references, there is this example:

{{< ref "document.md#anchor" >}} which is the same style that I was using that was working until the version change.

I might rework it to try using it instead.

.GetPage "members.md" (the Page method) will now only do relative lookups, which is what most people would expect.

This was changed in v0.65. I believe it is the reason why the code broke. So, not a bug.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.