Skip to content

Commit 793f4c3

Browse files
committed
feat: Add new util that returns the abs url and forces the protocol
1 parent f8ac8b5 commit 793f4c3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{/*
2+
utils/get-abs-url
3+
Returns an absolute URL with forced https prototol.
4+
5+
@returns Sring
6+
7+
@example - Go Template
8+
{{ partial "utils/get-abs-url" .url }}
9+
*/}}
10+
{{ $url := . }}
11+
12+
{{/* Creates an absolute URL based on the configured baseURL. */}}
13+
{{ $url = . | absURL }}
14+
15+
{{/* Adds https prototcol if the url starts with // and is not localhost */}}
16+
{{ $url = cond (and (hasPrefix $url "//") (not (hasPrefix $url "//localhost"))) (print "https:" $url) $url }}
17+
18+
{{ return $url }}

0 commit comments

Comments
 (0)