Skip to content

Commit 19b3d3a

Browse files
authored
Merge pull request #27 from jungvonmatt/feature/23-clean-up-content-model
Clean up content model
2 parents 00bd60a + db3abe2 commit 19b3d3a

File tree

66 files changed

+882
-892
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+882
-892
lines changed

hugo-modules/core/layouts/storybook/single.stories.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
{{- $combinations := partial "combinations" (dict "list" $templateParams) }}
110110

111111
{{ $params := merge site.Params (dict
112-
"environment" (or (getenv "HUGO_ENVIRONMENT") hugo.Environment)
112+
"environment" (or (getenv "HUGO_ENV") hugo.Environment)
113113
) }}
114114
{{- $js := resources.Get "js/main.js" | js.Build (dict
115115
"format" "esm"

hugo-modules/core/utils/get-category-name.html

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

1010
{{- $result := "" -}}
1111

12-
{{- if hasPrefix $content_type "t-" -}}
12+
{{- if (or (eq $content_type "page") (hasPrefix $content_type "t-")) -}}
1313
{{- $result = "templates" -}}
1414
{{- else if hasPrefix $content_type "m-" -}}
1515
{{- $result = "modules" -}}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{/*
22
utils/get-data
3-
Get data from contentful data types.
3+
Get data from Contentful data types.
44

55
@example - Go Template
66
{{ partial "utils/get-data" (dict
@@ -23,8 +23,6 @@
2323
{{ $result = or (index $contents (string $entry_id)) (index $contents (print (string $entry_id) "." $folder)) dict }}
2424
{{ end }}
2525
{{ end }}
26-
27-
2826
{{ end }}
2927

3028
{{ return $result }}

hugo-modules/core/utils/get-page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{{ $content_type := .content_type }}
1313
{{ $page := dict }}
1414
{{ if and $content_type $entry_id }}
15-
{{ if (eq $content_type "page") }}
15+
{{ if (or (eq $content_type "page") (hasPrefix $content_type "t-")) }}
1616
{{ with index (where site.Pages "Params.sys.id" $entry_id) 0 }}
1717
{{ $page = . }}
1818
{{ end }}

hugo-modules/core/utils/get-params.html

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@
1414
{{ $content_type := .content_type }}
1515
{{ $params := dict }}
1616

17-
{{ if (eq $content_type "page") }}
18-
{{ $page := partial "utils/get-page" . }}
19-
{{ with $page }}
20-
{{ $params = .Params }}
21-
{{ end }}
17+
{{ $page := partial "utils/get-page" . }}
18+
{{ with $page }}
19+
{{ $params = .Params }}
2220
{{ else }}
2321
{{ $params = merge . (partial "utils/get-data" . )}}
2422
{{ end }}
2523

26-
27-
2824
{{ return $params }}

hugo-modules/core/utils/link.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
{{ end }}
4444

4545
{{/* Page content type */}}
46-
{{ else if eq .content_type "page" }}
46+
{{ else if (or (eq .content_type "page") (hasPrefix .content_type "t-")) }}
4747
{{ with partialCached "utils/get-page" . . }}
4848
{{ $return = (dict
4949
"href" (.Permalink | safeURL)

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

Lines changed: 55 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
TODO:
1616
- [ ] Improve type test on "events", `article` seems very opinated.
17-
- [ ] Find a reasonable default image when `site.Params.default_image` is not set.
17+
- [ ] Find a reasonable default image when `$settings.default_share_image` is not set.
1818
- [ ] Twitter can sport "author" handle on top of the site's. Devise a test for author?
1919
- [ ] Maybe consider another approach to set the twitter_card (summary, etc...)
2020
- [ ] Not sure about image size. Following https://docs.imgix.com/best-practices/improving-seo-traffic, we have a
@@ -27,9 +27,7 @@
2727

2828
{{/* Adding the seo map to scratch which will recieve SEO key/value pairs. */}}
2929
{{ $s := newScratch }}
30-
{{ $s.Set "seo" dict }}
31-
32-
30+
{{ $s.Set "seo" dict }}
3331

3432
{{ $seo_params := dict }}
3533
{{ with .Params.seo }}
@@ -38,33 +36,27 @@
3836
{{ $seo_params = . }}
3937
{{ end }}
4038
{{ end }}
41-
{{ with .Params.content }}
42-
{{ with partialCached "utils/get-params" . . }}
43-
{{ $seo_params = merge . $seo_params }}
44-
{{ end }}
45-
{{ end }}
4639

47-
{{ $config := partialCached "utils/seo/private/get-config" "seo/private/get-config" }}
40+
{{ $settings := partialCached "utils/get-settings" . }}
4841

4942
{{/* Dates
5043
----------------------------- */}}
51-
52-
{{ if not .PublishDate.IsZero }}
53-
{{ $s.SetInMap "seo" "published_time" (.PublishDate.Format "2006-01-02T15:04:05-07:00") }}
54-
{{ else if not .Date.IsZero }}
55-
{{ $s.SetInMap "seo" "published_time" (.Date.Format "2006-01-02T15:04:05-07:00") }}
56-
{{ else }}
44+
{{ if not .PublishDate.IsZero }}
45+
{{ $s.SetInMap "seo" "published_time" (.PublishDate.Format "2006-01-02T15:04:05-07:00") }}
46+
{{ else if not .Date.IsZero }}
47+
{{ $s.SetInMap "seo" "published_time" (.Date.Format "2006-01-02T15:04:05-07:00") }}
48+
{{ else }}
5749
{{ with .Params.sys.created_at }}
58-
{{ $s.SetInMap "seo" "published_time" (dateFormat "2006-01-02T15:04:05-07:00" .) }}
50+
{{ $s.SetInMap "seo" "published_time" (dateFormat "2006-01-02T15:04:05-07:00" .) }}
5951
{{ end }}
60-
{{ end }}
61-
{{ if not .Lastmod.IsZero }}
62-
{{ $s.SetInMap "seo" "updated_time" (.Lastmod.Format "2006-01-02T15:04:05-07:00") }}
52+
{{ end }}
53+
{{ if not .Lastmod.IsZero }}
54+
{{ $s.SetInMap "seo" "updated_time" (.Lastmod.Format "2006-01-02T15:04:05-07:00") }}
6355
{{ else }}
6456
{{ with .Params.sys.updated_at }}
65-
{{ $s.SetInMap "seo" "updated_time" (dateFormat "2006-01-02T15:04:05-07:00" .) }}
57+
{{ $s.SetInMap "seo" "updated_time" (dateFormat "2006-01-02T15:04:05-07:00" .) }}
6658
{{ end }}
67-
{{ end }}
59+
{{ end }}
6860

6961
{{/* Description
7062
----------------------------
@@ -84,7 +76,7 @@
8476
{{/* 3. Summary */}}
8577
{{ else if .Summary }}
8678
{{ $description = .Summary }}
87-
{{ else }}
79+
{{ else }}
8880
{{/* 4. site description */}}
8981
{{ $description = site.Params.Description }}
9082
{{ end }}
@@ -96,63 +88,61 @@
9688
{{ end }}
9789
{{ end }}
9890

99-
10091
{{/* Title
10192
----------------------------
10293
We use the following logic
103-
1. Every pages: `{.Title} | {site.Title}`
104-
2. Homepage: , only {site.Title} */}}
105-
{{ $title := .Title }}
94+
1. Every pages: `Page title | Global site title`
95+
2. Homepage: only `Global site title` */}}
96+
{{ $title := "" }}
10697
{{ with $seo_params.title }}
10798
{{ $title = . }}
10899
{{ end }}
109100
{{ if not .IsHome }}
110-
{{/* 1. `{.Title} | {.Site.Title}` */}}
111-
{{ $s.SetInMap "seo" "title" (printf "%s | %s" $title site.Title) }}
101+
{{/* 1. `Page title | Global site title` */}}
102+
{{ $s.SetInMap "seo" "title" (printf "%s | %s" $title $settings.title) }}
112103
{{ else }}
113-
{{/* 2. `{.Site.Title}` */}}
114-
{{ $s.SetInMap "seo" "title" site.Title }}
104+
{{/* 2. `Global site title` */}}
105+
{{ $s.SetInMap "seo" "title" $settings.title }}
115106
{{ end }}
116107

117-
118108
{{/* Site Name
119109
---------------------------- */}}
120-
{{ with $config.site_name }}
121-
{{ $s.SetInMap "seo" "site_name" . }}
110+
{{ with $settings.site_name }}
111+
{{ $s.SetInMap "seo" "site_name" $settings.site_name }}
122112
{{ else }}
123-
{{ $s.SetInMap "seo" "site_name" site.Title }}
113+
{{ $s.SetInMap "seo" "site_name" $settings.title }}
124114
{{ end }}
125115

126116
{{/* Image
127117
---------------------------- */}}
128118
{{ $img := false }}
129119

130-
{{ with $config.default_image }}
131-
{{ $img = . }}
132-
{{ end }}
120+
{{ with $settings.default_share_image }}
121+
{{ $img = .url }}
122+
{{ end }}
133123

134-
{{ with $seo_params.image }}
135-
{{ $img = . }}
124+
{{ with $seo_params.share_image }}
125+
{{ $img = .url }}
136126
{{ else }}
137127
{{/* If no SEO IMAGE is set, we look for the .Params.images slice
138128
and use the first one if it has an `image` key */}}
139-
{{ with .Params.images }}
140-
{{ with index . 0 }}
129+
{{ with .Params.images }}
130+
{{ with index . 0 }}
141131
{{ if reflect.IsMap . }}
142-
{{ with .image }}
143-
{{ $img = . }}
144-
{{ end }}
132+
{{ with .image }}
133+
{{ $img = .url }}
134+
{{ end }}
145135
{{ else }}
146-
{{ $img = . }}
136+
{{ $img = .url }}
147137
{{ end }}
148-
{{ end }}
149-
{{ end }}
150-
{{ end }}
138+
{{ end }}
139+
{{ end }}
140+
{{ end }}
151141

152142
{{/* Finally if after all of the conditional above we are not able to find an image for the page,
153143
we resolve to looking for the following: */}}
154144
{{ if not $img }}
155-
{{ $img_defaults := slice "/static/logo.jpg" "/static/logo.png" "/static/logo.svg" }}
145+
{{ $img_defaults := slice "/static/logo.jpg" "/static/logo.png" "/static/logo.svg" }}
156146
{{ range $path := $img_defaults }}
157147
{{ if fileExists . }}
158148
{{ $img = strings.TrimLeft "/static" $path }}
@@ -169,17 +159,16 @@
169159
---------------------------- */}}
170160
{{ with $img }}
171161
{{/* Most of the time we should have an image */}}
172-
{{ $s.SetInMap "seo" "twitter_card" "summary_large_image" }}
162+
{{ $s.SetInMap "seo" "twitter_card" "summary_large_image" }}
173163
{{ else }}
174164
{{/* For edge cases without: */}}
175-
{{ $s.SetInMap "seo" "twitter_card" "summary" }}
165+
{{ $s.SetInMap "seo" "twitter_card" "summary" }}
176166
{{ end }}
177167

178-
179168
{{/* We check the site config sports a Social.twitter and use as handle */}}
180-
{{ with .Site.Social.twitter }}
181-
{{ $s.SetInMap "seo" "twitter_handle" (printf "@%s" .) }}
182-
{{ end }}
169+
{{ with .Site.Social.twitter }}
170+
{{ $s.SetInMap "seo" "twitter_handle" (printf "@%s" .) }}
171+
{{ end }}
183172

184173
{{/* We check if the page is not set as private */}}
185174
{{ with $.Params.seo.private }}
@@ -191,28 +180,26 @@
191180

192181
{{/* Type
193182
---------------------------- */}}
194-
{{ $s.SetInMap "seo" "type" "website" }}
183+
{{ $s.SetInMap "seo" "type" "website" }}
195184

196-
{{ if in (slice "blog" "news") .Type }}
197-
{{ $s.SetInMap "seo" "type" "article" }}
185+
{{ if in (slice "blog" "news") .Type }}
186+
{{ $s.SetInMap "seo" "type" "article" }}
198187
{{ else if in (slice "article") .Type }}
199-
{{ $s.SetInMap "seo" "type" "event" }}
200-
{{ end }}
201-
188+
{{ $s.SetInMap "seo" "type" "event" }}
189+
{{ end }}
202190

203-
{{/* robots
191+
{{/* Robots
204192
---------------------------- */}}
205193
{{ with $seo_params }}
206194
{{ $no_index := .no_index | default false }}
207195
{{ $no_follow := .no_follow | default false }}
208-
{{ $s.SetInMap "seo" "no_index" $no_index }}
209-
{{ $s.SetInMap "seo" "no_follow" $no_follow }}
196+
{{ $s.SetInMap "seo" "no_index" $no_index }}
197+
{{ $s.SetInMap "seo" "no_follow" $no_follow }}
210198
{{ end -}}
211199

212-
213200
{{/* Locale and translations
214201
---------------------------- */}}
215-
{{ $s.SetInMap "seo" "locale" .Lang }}
202+
{{ $s.SetInMap "seo" "locale" .Lang }}
216203

217204
{{ $translations := slice }}
218205
{{ if .IsTranslated }}
@@ -222,21 +209,15 @@
222209
{{ $s.SetInMap "seo" "translations" $translations }}
223210
{{ end }}
224211

225-
226212
{{/* Canonical
227213
---------------------------- */}}
228-
{{ with $seo_params.canonical }}
229-
{{ $s.SetInMap "seo" "canonical" (. | absURL) }}
230-
{{ else }}
231-
{{ $s.SetInMap "seo" "canonical" .Permalink }}
232-
{{ end }}
214+
{{ $s.SetInMap "seo" "canonical" .Permalink }}
233215

234216
{{ $seo := $s.Get "seo" }}
235217
{{ if templates.Exists "partials/utils/seo/data.html" }}
236218
{{ $seo = partial "utils/seo/data" (dict "seo" $seo "Page" $) }}
237219
{{ end }}
238220

239-
240221
{{ with $seo }}
241222
{{ $s.SetInMap "jsonld" "@context" "https://schema.org" }}
242223
{{ $s.SetInMap "jsonld" "@type" .type }}
@@ -254,7 +235,4 @@
254235
{{ $seo = merge $seo (dict "jsonld" .) }}
255236
{{ end }}
256237

257-
258-
259-
260238
{{ return $seo }}

0 commit comments

Comments
 (0)