Skip to content

Commit cfd01e3

Browse files
authored
Merge pull request #57 from jungvonmatt/develop
Release v0.11.0
2 parents e43e1c3 + 58bcc6a commit cfd01e3

File tree

6 files changed

+40
-9
lines changed

6 files changed

+40
-9
lines changed

hugo-modules/core/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[Hugo](https://gohugo.io/) templates and utilities that support [Contentful](https://www.contentful.com/) and/or [Storybook](https://storybook.js.org/) projects.
44

5-
- [wekit-core](#wekit-core)
5+
- [WEKit core](#wekit-core)
66
- [Utils](#utils)
77
- [asset](#asset)
88
- [svg/icon](#svgicon)
@@ -11,6 +11,7 @@
1111
- [console/error](#consoleerror)
1212
- [console/warn](#consolewarn)
1313
- [dump](#dump)
14+
- [get-abs-url](#get-abs-url)
1415
- [get-category-name](#get-category-name)
1516
- [get-data](#get-data)
1617
- [get-page](#get-page)
@@ -28,14 +29,15 @@
2829
- [Layouts](#layouts)
2930
- [storybook](#storybook)
3031
- [robots.txt](#robotstxt)
32+
- [Contributors](#contributors)
3133
- [Credits](#credits)
3234

3335
## Utils
3436

3537
### asset
3638

3739
Render Contentful asset. Uses data from [cssg-plugin-assets](https://github.com/jungvonmatt/contentful-ssg/tree/main/packages/cssg-plugin-assets) if available.
38-
Uses `svg/icon` when the inline options is set and we got an svg,
40+
Uses `svg/icon` when the inline options is set and we got an svg,
3941
*Template*
4042

4143
```
@@ -119,6 +121,16 @@ Dump variable as highlighted yaml.
119121
{{ partial "utils/dump" .context }}
120122
```
121123

124+
### get-abs-url
125+
126+
Returns an absolute URL with forced https prototol.
127+
128+
*Template*
129+
130+
```
131+
{{ partial "utils/get-abs-url" .url }}
132+
```
133+
122134
### get-category-name
123135

124136
Get category name by prefix of `content_type`.

hugo-modules/core/utils/asset/image/img.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
{{- end -}}
5656
{{- else -}}
5757
{{- with $url -}}
58-
{{- $src := $params.src | default (cond (hasPrefix . "//") (print "https:" .) .) -}}
58+
{{- $absUrl := partial "utils/get-abs-url" . -}}
59+
{{- $src := $params.src | default $absUrl -}}
5960
<img src="{{- $src -}}" width="{{- $width -}}" height="{{- $height -}}" {{ $image_attributes }} alt="{{- $alt -}}"{{ with $params.preload }} fetchpriority="high"{{ end }}>
6061
{{/* Add preload hint here as we have no srcset available */}}
6162
{{- $preload_attr := (dict
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 }}

hugo-modules/core/utils/link.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
{{/* context is url */}}
1111
{{ if partialCached "utils/reflect/is-string" . . }}
12-
{{ $href := cond (and (hasPrefix . "//") (not (hasPrefix . "//localhost")) ) (print "https:" . ) . }}
12+
{{ $href := partial "utils/get-abs-url" . }}
1313
{{ $return = (dict "href" $href) }}
1414
{{/* Add target="_blank" and rel="noreferrer" for external links */}}
1515
{{ if (and (in . "//") (not (in . site.BaseURL))) }}

hugo-modules/core/utils/seo/private/get-data.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,22 +133,22 @@
133133
{{ $img := false }}
134134

135135
{{ with $settings.default_share_image }}
136-
{{ $img = .url }}
136+
{{ $img = partial "utils/get-abs-url.html" .url }}
137137
{{ end }}
138138

139139
{{ with $seo_params.share_image }}
140-
{{ $img = .url }}
140+
{{ $img = partial "utils/get-abs-url.html" .url }}
141141
{{ else }}
142142
{{/* If no SEO IMAGE is set, we look for the .Params.images slice
143143
and use the first one if it has an `image` key */}}
144144
{{ with .Params.images }}
145145
{{ with index . 0 }}
146146
{{ if reflect.IsMap . }}
147147
{{ with .image }}
148-
{{ $img = .url }}
148+
{{ $img = partial "utils/get-abs-url.html" .url }}
149149
{{ end }}
150150
{{ else }}
151-
{{ $img = .url }}
151+
{{ $img = partial "utils/get-abs-url.html" .url }}
152152
{{ end }}
153153
{{ end }}
154154
{{ end }}

hugo-modules/core/utils/svg/parse.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
{{ end }}
5555
{{ end }}
5656
{{ with .url }}
57-
{{ $src = cond (hasPrefix . "//") (print "https:" .) . }}
57+
{{ $src := partial "utils/get-abs-url" . }}
5858
{{ with resources.GetRemote $src }}
5959
{{ $src = .RelPermalink }}
6060
{{ $source = .Content }}

0 commit comments

Comments
 (0)