|
14 | 14 |
|
15 | 15 | TODO:
|
16 | 16 | - [ ] 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. |
18 | 18 | - [ ] Twitter can sport "author" handle on top of the site's. Devise a test for author?
|
19 | 19 | - [ ] Maybe consider another approach to set the twitter_card (summary, etc...)
|
20 | 20 | - [ ] Not sure about image size. Following https://docs.imgix.com/best-practices/improving-seo-traffic, we have a
|
|
27 | 27 |
|
28 | 28 | {{/* Adding the seo map to scratch which will recieve SEO key/value pairs. */}}
|
29 | 29 | {{ $s := newScratch }}
|
30 |
| -{{ $s.Set "seo" dict }} |
31 |
| - |
32 |
| - |
| 30 | +{{ $s.Set "seo" dict }} |
33 | 31 |
|
34 | 32 | {{ $seo_params := dict }}
|
35 | 33 | {{ with .Params.seo }}
|
|
38 | 36 | {{ $seo_params = . }}
|
39 | 37 | {{ end }}
|
40 | 38 | {{ end }}
|
41 |
| -{{ with .Params.content }} |
42 |
| - {{ with partialCached "utils/get-params" . . }} |
43 |
| - {{ $seo_params = merge . $seo_params }} |
44 |
| - {{ end }} |
45 |
| -{{ end }} |
46 | 39 |
|
47 |
| -{{ $config := partialCached "utils/seo/private/get-config" "seo/private/get-config" }} |
| 40 | +{{ $settings := partialCached "utils/get-settings" . }} |
48 | 41 |
|
49 | 42 | {{/* Dates
|
50 | 43 | ----------------------------- */}}
|
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 }} |
57 | 49 | {{ 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" .) }} |
59 | 51 | {{ 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") }} |
63 | 55 | {{ else }}
|
64 | 56 | {{ 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" .) }} |
66 | 58 | {{ end }}
|
67 |
| -{{ end }} |
| 59 | +{{ end }} |
68 | 60 |
|
69 | 61 | {{/* Description
|
70 | 62 | ----------------------------
|
|
84 | 76 | {{/* 3. Summary */}}
|
85 | 77 | {{ else if .Summary }}
|
86 | 78 | {{ $description = .Summary }}
|
87 |
| -{{ else }} |
| 79 | +{{ else }} |
88 | 80 | {{/* 4. site description */}}
|
89 | 81 | {{ $description = site.Params.Description }}
|
90 | 82 | {{ end }}
|
|
96 | 88 | {{ end }}
|
97 | 89 | {{ end }}
|
98 | 90 |
|
99 |
| - |
100 | 91 | {{/* Title
|
101 | 92 | ----------------------------
|
102 | 93 | 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 := "" }} |
106 | 97 | {{ with $seo_params.title }}
|
107 | 98 | {{ $title = . }}
|
108 | 99 | {{ end }}
|
109 | 100 | {{ 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) }} |
112 | 103 | {{ else }}
|
113 |
| - {{/* 2. `{.Site.Title}` */}} |
114 |
| - {{ $s.SetInMap "seo" "title" site.Title }} |
| 104 | + {{/* 2. `Global site title` */}} |
| 105 | + {{ $s.SetInMap "seo" "title" $settings.title }} |
115 | 106 | {{ end }}
|
116 | 107 |
|
117 |
| - |
118 | 108 | {{/* Site Name
|
119 | 109 | ---------------------------- */}}
|
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 }} |
122 | 112 | {{ else }}
|
123 |
| - {{ $s.SetInMap "seo" "site_name" site.Title }} |
| 113 | + {{ $s.SetInMap "seo" "site_name" $settings.title }} |
124 | 114 | {{ end }}
|
125 | 115 |
|
126 | 116 | {{/* Image
|
127 | 117 | ---------------------------- */}}
|
128 | 118 | {{ $img := false }}
|
129 | 119 |
|
130 |
| -{{ with $config.default_image }} |
131 |
| - {{ $img = . }} |
132 |
| -{{ end }} |
| 120 | +{{ with $settings.default_share_image }} |
| 121 | + {{ $img = .url }} |
| 122 | +{{ end }} |
133 | 123 |
|
134 |
| -{{ with $seo_params.image }} |
135 |
| - {{ $img = . }} |
| 124 | +{{ with $seo_params.share_image }} |
| 125 | + {{ $img = .url }} |
136 | 126 | {{ else }}
|
137 | 127 | {{/* If no SEO IMAGE is set, we look for the .Params.images slice
|
138 | 128 | 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 }} |
141 | 131 | {{ if reflect.IsMap . }}
|
142 |
| - {{ with .image }} |
143 |
| - {{ $img = . }} |
144 |
| - {{ end }} |
| 132 | + {{ with .image }} |
| 133 | + {{ $img = .url }} |
| 134 | + {{ end }} |
145 | 135 | {{ else }}
|
146 |
| - {{ $img = . }} |
| 136 | + {{ $img = .url }} |
147 | 137 | {{ end }}
|
148 |
| - {{ end }} |
149 |
| - {{ end }} |
150 |
| -{{ end }} |
| 138 | + {{ end }} |
| 139 | + {{ end }} |
| 140 | +{{ end }} |
151 | 141 |
|
152 | 142 | {{/* Finally if after all of the conditional above we are not able to find an image for the page,
|
153 | 143 | we resolve to looking for the following: */}}
|
154 | 144 | {{ 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" }} |
156 | 146 | {{ range $path := $img_defaults }}
|
157 | 147 | {{ if fileExists . }}
|
158 | 148 | {{ $img = strings.TrimLeft "/static" $path }}
|
|
169 | 159 | ---------------------------- */}}
|
170 | 160 | {{ with $img }}
|
171 | 161 | {{/* 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" }} |
173 | 163 | {{ else }}
|
174 | 164 | {{/* For edge cases without: */}}
|
175 |
| - {{ $s.SetInMap "seo" "twitter_card" "summary" }} |
| 165 | + {{ $s.SetInMap "seo" "twitter_card" "summary" }} |
176 | 166 | {{ end }}
|
177 | 167 |
|
178 |
| - |
179 | 168 | {{/* 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 }} |
183 | 172 |
|
184 | 173 | {{/* We check if the page is not set as private */}}
|
185 | 174 | {{ with $.Params.seo.private }}
|
|
191 | 180 |
|
192 | 181 | {{/* Type
|
193 | 182 | ---------------------------- */}}
|
194 |
| -{{ $s.SetInMap "seo" "type" "website" }} |
| 183 | +{{ $s.SetInMap "seo" "type" "website" }} |
195 | 184 |
|
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" }} |
198 | 187 | {{ else if in (slice "article") .Type }}
|
199 |
| - {{ $s.SetInMap "seo" "type" "event" }} |
200 |
| -{{ end }} |
201 |
| - |
| 188 | + {{ $s.SetInMap "seo" "type" "event" }} |
| 189 | +{{ end }} |
202 | 190 |
|
203 |
| -{{/* robots |
| 191 | +{{/* Robots |
204 | 192 | ---------------------------- */}}
|
205 | 193 | {{ with $seo_params }}
|
206 | 194 | {{ $no_index := .no_index | default false }}
|
207 | 195 | {{ $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 }} |
210 | 198 | {{ end -}}
|
211 | 199 |
|
212 |
| - |
213 | 200 | {{/* Locale and translations
|
214 | 201 | ---------------------------- */}}
|
215 |
| -{{ $s.SetInMap "seo" "locale" .Lang }} |
| 202 | +{{ $s.SetInMap "seo" "locale" .Lang }} |
216 | 203 |
|
217 | 204 | {{ $translations := slice }}
|
218 | 205 | {{ if .IsTranslated }}
|
|
222 | 209 | {{ $s.SetInMap "seo" "translations" $translations }}
|
223 | 210 | {{ end }}
|
224 | 211 |
|
225 |
| - |
226 | 212 | {{/* Canonical
|
227 | 213 | ---------------------------- */}}
|
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 }} |
233 | 215 |
|
234 | 216 | {{ $seo := $s.Get "seo" }}
|
235 | 217 | {{ if templates.Exists "partials/utils/seo/data.html" }}
|
236 | 218 | {{ $seo = partial "utils/seo/data" (dict "seo" $seo "Page" $) }}
|
237 | 219 | {{ end }}
|
238 | 220 |
|
239 |
| - |
240 | 221 | {{ with $seo }}
|
241 | 222 | {{ $s.SetInMap "jsonld" "@context" "https://schema.org" }}
|
242 | 223 | {{ $s.SetInMap "jsonld" "@type" .type }}
|
|
254 | 235 | {{ $seo = merge $seo (dict "jsonld" .) }}
|
255 | 236 | {{ end }}
|
256 | 237 |
|
257 |
| - |
258 |
| - |
259 |
| - |
260 | 238 | {{ return $seo }}
|
0 commit comments