{{- $destination := .Destination }}
{{- $isRemote := or (or (in $destination ":") (strings.HasPrefix $destination "www")) (strings.HasPrefix $destination "//") }}
Should equal true for [essai](www.aol.fr) ? It doesn’t.
Complete code:
{{- $destination := .Destination }}
{{- $isRemote := or (in $destination ":") (strings.HasPrefix $destination "www") (strings.HasPrefix $destination "//") }}
{{- if not $isRemote }}
{{- $url := urls.Parse .Destination }}
{{- $path := strings.TrimSuffix "/_index.md" $url.Path }}
{{- $path = strings.TrimSuffix "/_index" $path }}
{{- $path = strings.TrimSuffix ".md" $path }}
{{- $page := site.GetPage $path }}
{{- if $page }}
{{- $destination = $page.RelPermalink }}
{{- if $url.Fragment }}
{{- $destination = print $destination "#" $url.Fragment }}
{{- end }}
{{- else if fileExists (print .Page.File.Dir .Destination) }}
<!-- Nothing -->
{{- else -}}
{{ with resources.Get .Destination }}
{{$destination = .RelPermalink}}
{{end}}
{{- end }}
{{- end }}
<a href="{{ $destination }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
By the way, why can’t conditionals like or, andif have multiple operands ? It would simplify writing. Otherwise, this works perfectly, no need for relref, nor giving the path for images. It finds the resource wherever it is, pages assets or static.
Ahah no, I just forgot to escape it.
Ok I just followed someone’s code without trying.
However, {{- $isRemote := or (in $destination ":") (strings.HasPrefix $destination "www") (strings.HasPrefix $destination "//") }} doesn’t make it see www.aol.fr as a remote link either.
Yeah I made a mistake, sorry.
But neither the first one or {{- $isRemote := or (in $destination ":") (strings.HasPrefix $destination "www") (strings.HasPrefix $destination "//") }}
work.
It worked for me too, but I lacked safeURL.
Ok, I understood that I had two issues. First off, this one: have the same issue that:
solved {{with | safeURL}}.
Then I thought resources.Get .Destination could work like .Get and find the resource with only the name, without the path. I was wrong. Now it’s perfect.
Thanks !