Skip to content

Commit

Permalink
refactor: render link
Browse files Browse the repository at this point in the history
  • Loading branch information
eallion committed Nov 6, 2024
1 parent 6af0719 commit edb21ae
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions layouts/_default/_markup/render-link.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{{ $url := urls.Parse .Destination }}
{{ $host := lower $url.Host }}
{{- if or (hasSuffix $host "eallion.com") (hasSuffix $host "e5n.cc") (hasSuffix $host "gov.cn") }}
<a href="{{ .Destination }}" target="_blank" rel="noopener noreferrer" {{ with .Title }}title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
{{- else if or (hasSuffix $host "www.eallion.com") (hasPrefix .Destination "#") -}}
<a href="{{ .Destination }}" {{ with .Title }}title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
{{- else -}}
<a href="/go/?target={{ .Destination | base64Encode }}" target="_blank" rel="noopener noreferrer" {{ with .Title }}title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
{{- end -}}

{{ if or (eq $url.Scheme "http") (eq $url.Scheme "https") }}
{{- if or (hasSuffix $host "eallion.com") (hasSuffix $host "e5n.cc") (hasSuffix $host "gov.cn") (hasSuffix $host "creativecommons.org") (hasSuffix $host "kubaicai.com") }}
<a href="{{ .Destination }}" target="_blank" rel="noopener noreferrer" {{ with .Title }}title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
{{- else if or (hasSuffix $host "www.eallion.com") (hasPrefix .Destination "#") -}}
<a href="{{ .Destination }}" {{ with .Title }}title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
{{- else -}}
<a href="/go/?target={{ .Destination | base64Encode }}" target="_blank" rel="noopener noreferrer" {{ with .Title }}title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
{{- end -}}
{{ else }}
<a href="{{ .Destination }}" {{ with .Title }}title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
{{ end }}

0 comments on commit edb21ae

Please sign in to comment.