fix: Les liens internes pouvaient être cassé

This commit is contained in:
Simon 2020-12-03 16:58:35 +01:00
parent 3c20b9a271
commit 661171af40
1 changed files with 6 additions and 6 deletions

View File

@ -2,16 +2,18 @@
S'il n'y a pas de / dans l'url d'un lien alors on ajoute le path du répertoire
*/}}
{{ $isExternalLink := strings.HasPrefix .Destination "http" }}
{{ $isNotWebLink := or (not $isExternalLink) (eq 1 (strings.Count .Destination ":")) }}
{{ $isWebLink := or $isExternalLink (eq 0 (.Destination | strings.Count ":")) }}
{{ $isTelLink := strings.HasPrefix .Destination "tel:" }}
{{ $isMailtoLink := strings.HasPrefix .Destination "mailto:" }}
{{ $hasSlash := in .Destination "/" }}
{{ $link := cond (or (or $isExternalLink $isNotWebLink) $hasSlash) .Destination (path.Join "/" .Page.Dir .Destination) }}
{{ if $isNotWebLink }}
{{ if $isWebLink }}
{{ $link := cond (and $isWebLink (and (not $hasSlash) (not $isExternalLink))) (path.Join "/" .Page.Dir .Destination) .Destination }}
<a href="{{ $link | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if $isExternalLink }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>
{{ else }}
{{- $separators := cond $isMailtoLink ":@." ":" -}}
{{- $regex := cond $isMailtoLink "[a-z]*:(.*)" "[a-z]*:([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})"}}
{{- $replace := cond $isMailtoLink "$1" "$1 $2 $3 $4 $5" -}}
{{- $string := $link -}}
{{- $string := .Destination -}}
{{- $params := slice -}}
{{- range split $separators "" }}
@ -30,6 +32,4 @@
data-replace="{{ $replace }}"
>
</span>
{{ else }}
<a href="{{ $link | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if $isExternalLink }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>
{{ end }}