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

docs: improve rendering of links for local markdown files #1177

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
docs: improve rendering of links for local markdownfiles
Hugo is not really good when it comes to linking markdown files,
if they are not within an own folder. With this improvement, we
will fetch all relative links, even with `.md` and generate their
url different than the [originial version](https://gohugo.io/templates/render-hooks/#link-with-title-markdown-example).

Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com>
aepfli committed Apr 4, 2023
commit c64845404492eb86fb156834c8ca008b306f7649
13 changes: 13 additions & 0 deletions docs/layouts/_default/_markup/render-link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if or (strings.HasPrefix .Destination "http") (strings.HasPrefix .Destination "#") -}}
<a href="{{ .Destination | safeURL }}"{{ with .Title }} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
{{- else -}}
{{- $link := . -}}
{{- $internal := urls.Parse .Destination -}}
{{- if $internal.Path -}}
{{- $fragment := "" }}
{{- with $internal.Fragment }}{{ $fragment = printf "#%s" . }}{{ end -}}
{{- with .Page.GetPage $internal.Path }}{{ $internal = printf "%s%s" .RelPermalink $fragment }}
<a href="{{ $internal }}"{{ with .Title }} title="{{ . }}"{{ end }}>{{ $link.Text | safeHTML }}</a>
{{- end -}}
{{- end -}}
{{- end -}}