Skip to content

Commit

Permalink
docs: improve rendering of links for local markdown files (#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
aepfli authored Apr 4, 2023
1 parent 4480444 commit 070bbee
Showing 1 changed file with 13 additions and 0 deletions.
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 -}}

0 comments on commit 070bbee

Please sign in to comment.