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

Render link hook shouldn't rewrite paths #270

Closed
chalin opened this issue May 5, 2021 · 0 comments · Fixed by #420
Closed

Render link hook shouldn't rewrite paths #270

chalin opened this issue May 5, 2021 · 0 comments · Fixed by #420

Comments

@chalin
Copy link
Contributor

chalin commented May 5, 2021

The render-link hook is currently rewriting URL paths for non-external links using the .GetPage feature (see line 8 below):

{{ $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 -}}
<a href="{{ $link | safeURL }}"
{{- with .Title}} title="{{ . }}"{{ end -}}
{{- if $isRemote }} target="_blank" rel="noopener"{{ end -}}
>
{{- .Text | safeHTML -}}
</a>

IMHO, the render-link hook is useful for changing the appearance of links (e.g., see #269), but it shouldn't rewrite URLs. The relref internal Hugo function should be used instead if/when we want to rewrite paths based on page lookups.

This might be a vestige of the time when the docs were a part of the etcd repo rather than here under the website repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants