🔀 Merge pull request #691 from stereobooster/portable-links-2

Print warning if system can't resolve link to a markdown file
pull/723/head
James Panther 2023-11-26 16:23:01 +11:00 committed by GitHub
commit 041fc30fe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -2,10 +2,16 @@
{{- $isRemote := strings.HasPrefix $link "http" -}} {{- $isRemote := strings.HasPrefix $link "http" -}}
{{- if not $isRemote }} {{- if not $isRemote }}
{{ $url := urls.Parse .Destination }} {{ $url := urls.Parse .Destination }}
{{ if $url.Path }} {{- if $url.Path }}
{{ $fragment := "" }} {{ $fragment := "" }}
{{- with $url.Fragment }}{{ $fragment = printf "#%s" . }}{{ end -}} {{- with $url.Fragment }}{{ $fragment = printf "#%s" . }}{{ end -}}
{{- with .Page.GetPage $url.Path }}{{ $link = printf "%s%s" .RelPermalink $fragment }}{{ end -}} {{- with .Page.GetPage $url.Path }}
{{ end }} {{ $link = printf "%s%s" .RelPermalink $fragment }}
{{ else }}
{{- if hasSuffix $url.Path ".md" }}
{{ warnf "Can't resolve: %s" .Destination }}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}} {{ end -}}
<a href="{{ $link | safeURL }}"{{ with .Title }} title="{{ . }}"{{ end }}{{ if $isRemote }} target="_blank" rel="noreferrer"{{ end }}>{{- .Text | safeHTML -}}</a> <a href="{{ $link | safeURL }}"{{ with .Title }} title="{{ . }}"{{ end }}{{ if $isRemote }} target="_blank" rel="noreferrer"{{ end }}>{{- .Text | safeHTML -}}</a>