Prevent treating files starting with http as external links
Some checks are pending
Deploy Hugo site to Pages / build (push) Waiting to run
Deploy Hugo site to Pages / deploy (push) Blocked by required conditions
Deploy Hugo site to Pages / ipfs-publish (push) Blocked by required conditions

This commit is contained in:
JP Hastings-Spital 2024-11-23 18:26:16 +00:00
parent 6a84655f46
commit 19ab7f85e0

View file

@ -1,6 +1,6 @@
{{- $url := .url -}} {{- $url := .url -}}
{{- $title := .Title -}} {{- $title := .Title -}}
{{- $isExternal := strings.HasPrefix $url "http" -}} {{- $isExternal := or (strings.HasPrefix $url "https://") (strings.HasPrefix $url "http://") -}}
{{- $text := .Text | default $url -}} {{- $text := .Text | default $url -}}
{{/* It pains me that Hugo doesn't have a urls.IsValid method, and has no error catching to allow me to try urls.Parse and catch failures */}} {{/* It pains me that Hugo doesn't have a urls.IsValid method, and has no error catching to allow me to try urls.Parse and catch failures */}}
{{- if gt (len (strings.FindRE `^https?:\/\/[A-z0-9_-]*?[:]?[A-z0-9_-]*?[@]?[A-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$` $text)) 0 -}} {{- if gt (len (strings.FindRE `^https?:\/\/[A-z0-9_-]*?[:]?[A-z0-9_-]*?[@]?[A-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$` $text)) 0 -}}