Welcome to mirror list, hosted at ThFree Co, Russian Federation.

head.html « partials « layouts - gitlab.com/rmaguiar/hugo-theme-color-your-world.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9e1132245030a7fdf5727242f4b60e172636b934 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="generator" content="Hugo {{ hugo.Version }}">
<meta name="theme" content="Color Your World -- gitlab.com/rmaguiar/hugo-theme-color-your-world">

<!-- I'm 99% sure there's a smarter way of doing it but whatever -->
{{ $currentTitle  := .Title | emojify }}
{{ $mainTitle     := .Params.mainTitle | emojify }}


{{ $titleSeparator := .Site.Params.titleSeparator }}


{{ if (eq .Kind "404") }}

  <!-- If 404 page -->
  {{ $currentTitle = .Site.Params.notFound.title | emojify | default .Site.Data.default.notFound.title }}
  
{{ else if (eq .Kind "section") }}

  <!-- If post list -->
  {{ if gt .Paginator.TotalPages 1 }}
    {{ $mainTitle = printf `%s, %s %s %s %s` .Title (T "page") (string .Paginator.PageNumber) (T "of") (string .Paginator.TotalPages) }}
  {{ end }}
  
{{ else if eq .Kind "term" }}

  {{ $currentTerm := "" }}

  {{ if eq .Type "tags" }}
    {{ $currentTerm = (T "tag") }}
  {{ else }}
    {{ $currentTerm = (T "category") }}
  {{ end }}
  
  {{ $currentTitle = printf `%s: "%s"` $currentTerm .Title }}
  
  {{ with .Paginator }}
    {{ if gt .TotalPages 1 }}
      {{ $mainTitle = printf `%s: "%s", %s %s %s %s` $currentTerm $.Title (T "page") (string .PageNumber) (T "of") (string .TotalPages) }}
    {{ else }}
      {{ $mainTitle = printf `%s: "%s"` $currentTerm $.Title }}
    {{ end }}
  {{ end }}

{{ else if eq .Kind "taxonomy" }}

  {{ if eq .Type "tags" }}
    {{ $currentTitle = (T "tags") }}
  {{ else }}
    {{ $currentTitle = (T "categories") }}
  {{ end }}

{{ else if and (.IsHome) (not .Content) }}

  <!-- If home page without content -->
  {{ $currentTitle = .Site.Title | emojify }}

{{ end }}


{{ $currentDesc := .Params.Description | emojify }}

{{ if .IsHome }}
  {{ $currentDesc = .Site.Params.description | emojify }}
{{ else if and (ne .Kind "taxonomy") (eq .Type "tags") (not .Params.description) }}
  {{ $currentDesc = (T "postsUnderTag" .) }}
{{ else if and (ne .Kind "taxonomy") (eq .Type "categories") (not .Params.description) }}
  {{ $currentDesc = (T "postsUnderCategory" .) }}
{{ else if eq .Kind "taxonomy" }}
  {{ $currentDesc = printf `%s %s.` (T "pageContaining") ($currentTitle | lower) }}
{{ else if (eq .Kind "404") }}
  {{ $currentDesc = .Site.Params.notFound.description | emojify | default .Site.Data.default.notFound.description }}
{{ end }}


<!-- Set current title -->
{{ .Scratch.Set "currentTitle" $currentTitle }}



<!-- Beginning of the SEO madness -->

<title>
  {{- if and $titleSeparator (not .Params.disableTitleSeparator ) -}}
    {{ if $mainTitle }}
      {{- $mainTitle = printf `%s %s %s` $mainTitle $titleSeparator .Site.Title -}}
    {{ else }}
      {{- $mainTitle = printf `%s %s %s` $currentTitle $titleSeparator .Site.Title -}}
    {{ end }}
  {{- end -}}
  
  {{- if $mainTitle -}}
    {{- $mainTitle -}}
  {{ else }}
    {{- $currentTitle -}}
  {{- end -}}
</title>


{{ with .Site.Params.author }}<meta name="author" content="{{ . }}">{{ end }}
{{ with $currentDesc }}<meta name="description" content="{{ . }}">{{ end }}


<meta name="robots" content="{{ if and (ne .Kind "404") (ne .Params.noindex true) }}index follow{{ else }}noindex follow{{ end }}">
<meta name="referrer" content="no-referrer-when-downgrade">


<!-- Canon -->
{{ if and (.IsPage) (not .Params.sitemapExclude) }}
  {{ if .Params.canonicalURL }}
    <link rel="canonical" href="{{ .Params.canonicalURL }}">
  {{ else if and (ne .Kind "404") (ne .Params.sitemapExclude true) }}
    <link rel="canonical" href="{{ .Permalink }}">
  {{ end }}
{{ else if (eq .Kind "section") }}
  <link rel="canonical" href="{{ .Paginator.URL | absURL }}">
  
  {{ if .Paginator.HasPrev }}
    <link rel="prev" href="{{ .Paginator.Prev.URL | absURL }}">
  {{ end }}
  
  {{ if .Paginator.HasNext }}
    <link rel="next" href="{{ .Paginator.Next.URL | absURL }}">
  {{ end }}
{{ end }}


<!-- If the user wants to add something (custom favicons, fonts, scripts, etc) -->
{{ if (templates.Exists "partials/custom/head-append.html") }}
  {{ partial "custom/head-append" . }}
{{ end }}


<!-- Open Graph / Twitter Card -->
<meta property="og:site_name" content="{{ .Site.Title }}">
<meta property="og:title" content="{{ $currentTitle }}">
{{ with $currentDesc }}<meta property="og:description" content="{{ . }}">{{ end }}

{{- if ne .Kind "404" }}
  <meta property="og:url" content="{{ .Permalink }}">
{{ end -}}



<!-- Image processing options -->
{{ $highRes := .Site.Params.imageProc.highRes | default .Site.Data.default.imageProc.highRes }}

<!-- Default image path -->
{{ $imgPath := .Page.Param "imgPath" }}

<!-- Generate images for Open Graph, Twitter Cards and also Schema.org -->
{{- if .Params.cover }}

  {{ $file := .Params.cover }}

  {{ if $imgPath }}
    {{ $file = path.Join $imgPath $file }}
  {{ end }}

  {{- with .Resources.GetMatch $file }}
    <meta property="og:image" content="{{ (.Fill "1200x630").Permalink }}">
    <meta property="og:image:width" content="1200">
    <meta property="og:image:height" content="630">
    {{ with $.Params.coverAlt }}
      <meta property="og:image:alt" content="{{ . }}">
    {{ end }}
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:image" content="{{ (.Fill "1280x640").Permalink }}">

    {{ if and (in $.Site.Params.mainSections $.Section) (not .Params.sitemapExclude) }}
      {{ $.Scratch.Set "schemaCover" (slice ((.Fill "1280x640").Permalink) ((.Fill "1200x630").Permalink) ((.Resize (index $highRes 0)).Permalink)) }}
    {{ end }}
    
  {{ end -}}
{{ else if .Site.Params.cover }}
  {{ with resources.Get (.Site.Params.cover | default "img/cover.jpg") }}
    <meta property="og:image" content="{{ (.Fill "1200x630").Permalink }}">
    <meta property="og:image:width" content="1200">
    <meta property="og:image:height" content="630">
    {{ with $.Site.Params.coverAlt }}
      <meta property="og:image:alt" content="{{ . }}">
    {{ end }}
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:image" content="{{ (.Fill "1280x640").Permalink }}">

    {{ if and (in $.Site.Params.mainSections $.Section) (not .Params.sitemapExclude) }}
      {{ $.Scratch.Set "schemaCover" (slice ((.Fill "1280x640").Permalink) ((.Fill "1200x630").Permalink) ((.Resize (index $highRes 0)).Permalink)) }}
    {{ end }}
    
  {{ end }}
{{ end -}}

<!-- More social crap -->
{{ if and (in .Site.Params.mainSections .Section) (.IsPage) (not .Params.sitemapExclude) }}
  <meta property="og:type" content="article">
  
  {{ if not .Date.IsZero }}
    <meta property="article:published_time" content="{{ .PublishDate.Format "2006-01-02" | safeHTML }}">
    <meta property="article:modified_time" content="{{ .Lastmod.Format "2006-01-02" | safeHTML }}">
    <meta property="og:updated_time" content="{{ .Lastmod.Format "2006-01-02" | safeHTML }}">
  {{ end }}

  {{ with .Params.author }}
    <meta property="article:author" content="{{ . }}">
  {{ end }}
  
  {{ with .Site.Params.Social.Centralized.twitter }}
    <meta name="twitter:creator" content="{{ printf "@%s" (index . 0) }}">
  {{ end}}
  
{{ else }}
  <meta property="og:type" content="website">
{{ end -}}

{{ with .Site.Params.Social.Centralized.twitter }}
  <meta name="twitter:site" content="{{ printf "@%s" (index . 0) }}">
{{ end }}



{{ with .Site.Params.locale }}
  <meta property="og:locale" content="{{ . }}">
{{ end }}

{{ if .Site.Config.Privacy.Twitter.EnableDNT }}
  <meta name="twitter:dnt" content="on">
{{ end }}


<!-- Feed -->
{{ with .OutputFormats.Get "RSS" }}
  <link rel="alternate" type="application/rss+xml" href="{{ .Permalink }}" title="{{ $.Site.Title }}">
{{ end }}


<!-- i18n -->
{{ if .IsTranslated }}
  {{ range .Translations }}
    <link rel="alternate" hreflang="{{ .Language.Lang }}" href="{{ .Permalink }}" title="{{ .Language.LanguageName }}">
  {{ end }}
{{ end }}


<!-- Will be replaced by JS anyway -->
<meta name="theme-color" content="#222">

<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">


<!-- Reduce repetition... -->
{{ $centralized   := .Site.Params.Social.Centralized }}
{{ $decentralized := .Site.Params.Social.Decentralized }}

<!-- Generate array with social profiles -->
{{ $sameAs := slice }}

{{ if .Site.Params.Social }}
  {{ range .Site.Data.social }}

    {{ $currentEntry  := .entry }}
    {{ $currentBase   := .base }}

    {{ if not .decentralized }}

      {{ with (index $centralized $currentEntry) }}
        {{ $sameAs = $sameAs | append (printf "%s%s" $currentBase (index . 0)) }}
      {{ end }}
      
    {{ else }}
    
      {{ if (index $decentralized $currentEntry) }}
        {{ range (index $decentralized $currentEntry) }}
          {{ $sameAs = $sameAs | append (index . 0) }}
        {{ end }}
      {{ end }}
      
    {{ end }}

  {{ end }}
{{ end }}

<!-- Schema Markup / Structured Data -->

<!--
  TODO
  The lack of "datePublished" will throw an error,
  but I don't know if leaving it as "0001-01-01" is any better.
  
  Also, there's something wrong with the Google's validation tool.
  It's ignoring the "Person" type for https://schema.org/publisher.
  
  Reference: https://www.drupal.org/project/schema_metatag/issues/3097526
-->

{{ if and (in .Site.Params.mainSections .Section) (.IsPage) (not .Params.sitemapExclude) }}
  <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "Article",
      "mainEntityOfPage": {
        "@type": "WebSite",
        "@id": "{{ .Site.BaseURL }}"
      },
      "headline": {{ $currentTitle }},
      "description": {{ $currentDesc }},
      {{ with .Scratch.Get "schemaCover" }}"image": {{ . }},{{ end }}
      "url": "{{ .Permalink }}",
      "inLanguage": "{{ .Site.Language.Lang }}",
      "datePublished": "{{ .PublishDate.Format "2006-01-02" | safeHTML }}",
      {{ with .Lastmod }}"dateModified": "{{ .Format "2006-01-02" | safeHTML }}",{{ end }}
      "wordCount" : "{{ .WordCount }}",
      "publisher": {
        "@type": "Person",
        "name": "{{ .Site.Params.author }}"
      },
      "author": {
        "@type": "Person",
        "name": "{{ .Site.Params.author }}",
        {{ with .Site.Params.authorDesc }}"description": {{ . }},{{ end }}
        {{ if gt (len $sameAs) 0 }}"sameAs": {{ $sameAs }}{{ end }}
      }
    }
  </script>
{{ else }}
  <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "WebSite",
      "url": "{{ .Site.BaseURL }}",
      "inLanguage": "{{ .Site.Language.Lang }}",
      "name": {{ .Site.Title }},
      "description": {{ .Site.Params.description | emojify }},
      "publisher": "{{ .Site.Params.author }}"
    }
  </script>
{{ end }}


<!-- Cached style -->
{{ partialCached "head-style" . }}

<!-- Preload fonts -->
{{ partialCached "font-preload" . }}

<!-- Preconnect for KaTeX -->
{{ if or .Params.katex .Site.Params.katex .Params.math .Site.Params.math }}
  <link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin="anonymous">
{{ end }}


<!--
  rel="me"
  Not even sure how useful is this nowdays,
  but since it's easy to implement...
-->

{{ range $sameAs }}
  <link rel="me" href="{{ . }}"> 
{{ end }}


<!--
  Priority JavaScript
  If not using Hugo server, remove every "console.log()"
-->

{{ with resources.Get "js/prepone.js" | resources.ExecuteAsTemplate .Page . }}

  <script>
    {{ if $.Site.IsServer }}
      {{ .Content | safeJS }}
    {{ else }}
      {{ .Content | replaceRE "console.log(.*?);" "" | safeJS }}
    {{ end }}
  </script>

{{ end }}