fix: Les liens internes pouvaient être cassé
This commit is contained in:
parent
3c20b9a271
commit
661171af40
|
@ -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 }}
|
||||
|
|
Loading…
Reference in New Issue