Skip to content

Commit

Permalink
🔀 Merge pull request #691 from stereobooster/portable-links-2
Browse files Browse the repository at this point in the history
Print warning if system can't resolve link to a markdown file
  • Loading branch information
jpanther authored Nov 26, 2023
2 parents a9f79b7 + e70c968 commit 041fc30
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions layouts/_default/_markup/render-link.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
{{- $isRemote := strings.HasPrefix $link "http" -}}
{{- if not $isRemote }}
{{ $url := urls.Parse .Destination }}
{{ if $url.Path }}
{{- if $url.Path }}
{{ $fragment := "" }}
{{- with $url.Fragment }}{{ $fragment = printf "#%s" . }}{{ end -}}
{{- with .Page.GetPage $url.Path }}{{ $link = printf "%s%s" .RelPermalink $fragment }}{{ end -}}
{{ end }}
{{- with .Page.GetPage $url.Path }}
{{ $link = printf "%s%s" .RelPermalink $fragment }}
{{ else }}
{{- if hasSuffix $url.Path ".md" }}
{{ warnf "Can't resolve: %s" .Destination }}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
<a href="{{ $link | safeURL }}"{{ with .Title }} title="{{ . }}"{{ end }}{{ if $isRemote }} target="_blank" rel="noreferrer"{{ end }}>{{- .Text | safeHTML -}}</a>

0 comments on commit 041fc30

Please sign in to comment.