35 lines
1.3 KiB
HTML
35 lines
1.3 KiB
HTML
{{- $text := .Text -}}
|
|
{{- $href := .Destination -}}
|
|
{{- $parsed := urls.Parse $href -}}
|
|
{{- if in (slice "http" "https") $parsed.Scheme -}}
|
|
{{- if eq .Destination .Text -}}
|
|
{{- $host := replaceRE `^www\.` "" $parsed.Host -}}
|
|
{{- $onlyPathHosts := slice "doi.org" "reddit.com" "github.com" -}}
|
|
{{- if in $onlyPathHosts (lower $host) }}
|
|
{{- $text = slicestr $parsed.Path 1 -}}
|
|
{{- else -}}
|
|
{{- $text = print $host $parsed.Path -}}
|
|
{{- end }}
|
|
{{- else -}}
|
|
{{- if and (eq $parsed.Host "transfemscience.org") (hasPrefix $parsed.Path "/articles/") }}
|
|
{{- $articleName := replaceRE `^/articles/(\S+)/$` "$1" $parsed.Path -}}
|
|
{{- with .Page.GetPage $articleName -}}
|
|
{{- if not .Params.hidden -}}
|
|
{{- $href = .Permalink -}}
|
|
{{- with $parsed.Fragment -}}
|
|
{{- $href = print $href "#" $parsed.EscapedFragment -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end }}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- if eq $parsed.Scheme "mailto" -}}
|
|
<a href="mailto:{{ $parsed.Opaque | base64Encode }}">{{ cond (eq $text $parsed.Opaque) "" $text | safeHTML }}</a>
|
|
{{- else -}}
|
|
{{- $external := hasPrefix ($href | relURL) "http" -}}
|
|
<a href="{{ $href | safeURL }}"
|
|
{{- with .Title }} title="{{ . }}"{{ end -}}
|
|
{{- if $external }} target="_blank"{{ end -}}
|
|
>{{ $text | safeHTML }}</a>
|
|
{{- end -}} |