feat(helper/image): better detection of external image

By using strings.HasPrefix, it matches any images which name starts with http
This commit is contained in:
Jimmy Cai 2020-09-10 23:24:19 +02:00
parent 19ff7a46bb
commit 3e18e165e0
No known key found for this signature in database
GPG Key ID: 3EA408E527F37B18

View File

@ -4,7 +4,8 @@
<!-- If page has `image` field set --> <!-- If page has `image` field set -->
{{ $result = merge $result (dict "exists" true) }} {{ $result = merge $result (dict "exists" true) }}
{{ if strings.HasPrefix $imageField "http" }} {{ $url := urls.Parse $imageField }}
{{ if or (eq $url.Scheme "http") (eq $url.Scheme "https") }}
<!-- Is a external image --> <!-- Is a external image -->
{{ $result = merge $result (dict "src" $imageField) }} {{ $result = merge $result (dict "src" $imageField) }}
{{ else }} {{ else }}