Skip to content

Commit af0077f

Browse files
authored
Merge pull request #48350 from sftim/20241015_tidy_page_head
Tidy <head> for pages
2 parents da0b312 + ee50a91 commit af0077f

File tree

3 files changed

+81
-74
lines changed

3 files changed

+81
-74
lines changed

layouts/partials/head.html

Lines changed: 38 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
{{- $isBlogPost := eq .Section "blog" }}
2-
{{- $ogType := cond (.IsHome) "website" "article" }}
1+
{{/* Adapted from Docsy; changes are to Google Analytics */}}
2+
{{/* OK to remove once using a modern enough Docsy (eg 0.11.0 or later) */}}
3+
<meta charset="utf-8">
4+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
5+
{{ hugo.Generator }}
6+
{{ range .AlternativeOutputFormats -}}
7+
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | safeURL }}">
8+
{{ end -}}
39

410
{{ $outputFormat := partial "outputformat.html" . -}}
511
{{ if and hugo.IsProduction (ne $outputFormat "print") -}}
@@ -8,80 +14,38 @@
814
<meta name="robots" content="noindex, nofollow">
915
{{ end -}}
1016

11-
<!-- alternative translations -->
12-
{{ range .Translations -}}
13-
<link rel="alternate" hreflang="{{ .Language.Lang }}" href="{{ .Permalink }}">
14-
{{ end -}}
15-
16-
<!-- Docsy head.html begins here -->
17-
<meta charset="utf-8">
18-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
19-
{{ hugo.Generator }}
20-
{{ range .AlternativeOutputFormats -}}
21-
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | safeURL }}">
22-
{{ end -}}
2317
{{ partialCached "favicons.html" . }}
24-
<title>{{ if .IsHome }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{ . }} | {{ end }}{{ .Site.Title }}{{ end }}</title>
25-
{{- template "_internal/opengraph.html" . -}}
26-
{{- template "_internal/schema.html" . -}}
27-
{{- template "_internal/twitter_cards.html" . -}}
28-
{{- if hugo.IsProduction -}}
29-
{{ template "_internal/google_analytics.html" . }}
30-
{{ end }}
31-
{{ partialCached "head-css.html" . "asdf" }}
32-
{{ if and (.Site.Params.offlineSearch) (not .Site.Params.gcs_engine_id) }}
33-
<script src="https://unpkg.com/[email protected]/lunr.js"></script>
34-
<script src="/js/offline-search.js"></script>
35-
{{end}}
36-
37-
<!-- Docsy head.html ends here -->
38-
39-
<script type="application/ld+json">
40-
{
41-
"@context": "https://schema.org",
42-
"@type": "Organization",
43-
"url": "https://kubernetes.io",
44-
"logo": "https://kubernetes.io/images/favicon.png",
45-
{{- if not .Site.Params.deprecated }}
46-
"potentialAction": {
47-
"@type": "SearchAction",
48-
"target": {{ printf "%s%s" ("search/" | absURL) "?q={search_term_string}" }},
49-
"query-input": "required name=search_term_string"
50-
}
51-
{{ end }}
52-
}
53-
</script>
54-
<meta name="theme-color" content="#326ce5">
55-
{{ partial "css.html" . }}
56-
<!-- Content for social media sharing previews -->
57-
<!-- Facebook uses the og: stuff, while Twitter and others use twitter: -->
18+
<title>
19+
{{- if .IsHome -}}
20+
{{ .Site.Title -}}
21+
{{ else -}}
22+
{{ with .Title }}{{ . }} | {{ end -}}
23+
{{ .Site.Title -}}
24+
{{ end -}}
25+
</title>
5826
<meta name="description" content="{{ template "partials/page-description.html" . }}">
59-
<meta property="og:description" content="{{ template "partials/page-description.html" . }}">
60-
<meta name="twitter:description" content="{{ template "partials/page-description.html" . }}">
61-
<meta property="og:url" content="{{ .Permalink }}">
62-
<meta property="og:title" content="{{ if .Params.title }}{{ .Title }}{{ else }}{{ .Summary | truncate 10 }}{{ end }}">
63-
<meta name="twitter:title" content="{{ if .Params.title }}{{ .Title }}{{ else }}{{ .Summary | truncate 10 }}{{ end }}">
64-
<meta name="twitter:image" content="https://kubernetes.io/images/favicon.png" />
65-
<!-- Alt text for the site image -->
66-
<meta name="twitter:image:alt" content="{{ site.Title }}">
67-
{{ if $isBlogPost }}
68-
{{ with findRE "<img.*?>" .Content 1 }}
69-
<meta property="og:image" content="{{ index . 0 | replaceRE ".*src=\"(.+?)\".*" "$1" }}">
70-
{{ end }}
71-
{{ else }}
72-
<meta property="og:image" content="{{ "/images/kubernetes-horizontal-color.png" | relURL }}">
73-
{{ end }}
74-
<meta property="og:type" content="{{ $ogType }}">
27+
{{ template "_internal/opengraph.html" . -}}
28+
{{ template "_internal/schema.html" . -}}
29+
{{ template "_internal/twitter_cards.html" . -}}
30+
{{ partialCached "head-css.html" . "asdf" -}}
31+
<script
32+
src="https://code.jquery.com/jquery-3.6.0.min.js"
33+
integrity="sha384-vtXRMe3mGCbOeY7l30aIg8H9p3GdeSe4IFlP6G8JMa7o7lXvnz3GFKzPxzJdPfGK"
34+
crossorigin="anonymous"></script>
35+
{{ if .Site.Params.offlineSearch -}}
36+
<script defer
37+
src="https://unpkg.com/[email protected]/lunr.min.js"
38+
integrity="sha384-203J0SNzyqHby3iU6hzvzltrWi/M41wOP5Gu+BiJMz5nwKykbkUx8Kp7iti0Lpli"
39+
crossorigin="anonymous"></script>
40+
{{ end -}}
7541

76-
<script src="/js/jquery-3.6.0.min.js" intregrity="sha384-vtXRMe3mGCbOeY7l30aIg8H9p3GdeSe4IFlP6G8JMa7o7lXvnz3GFKzPxzJdPfGK" crossorigin="anonymous"></script>
77-
<!--script src="https://unpkg.com/split.js/dist/split.min.js"></script-->
78-
<script src="/js/split-1.6.0.js" intregrity="sha384-0blL3GqHy6+9fw0cyY2Aoiwg4onHAtslAs4OkqZY7UQBrR65/K4gI+hxLdWDrjpz"></script>
42+
{{ if .Site.Params.prism_syntax_highlighting -}}
43+
<link rel="stylesheet" href="{{ "css/prism.css" | relURL }}"/>
44+
{{ end -}}
7945

80-
{{- if eq (lower .Params.cid) "community" -}}
81-
<script defer src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
82-
{{- end -}}
83-
{{ with .Params.js }}{{ range (split . ",") }}<script src="{{ (trim . " ") | relURL }}"></script><!-- custom js added -->
84-
{{ end }}{{ else }}<!-- no custom js detected -->{{ end }}
46+
{{ partial "hooks/head-end.html" . -}}
8547

86-
{{/* make sure that head-end hook comes last */}}
87-
{{ partial "hooks/head-end.html" . }}
48+
{{/* To comply with GDPR, cookie consent scripts places in head-end must execute before Google Analytics is enabled */ -}}
49+
{{ if hugo.IsProduction -}}
50+
{{ template "_internal/google_analytics.html" . }}
51+
{{ end -}}

layouts/partials/hooks/head-end.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
{{/* reference page-specific open graph image */}}
2+
{{- if ( eq .Section "blog" ) -}}
3+
{{ with findRE "<img.*?>" .Content 1 }}
4+
<meta property="og:image" content="{{ index . 0 | replaceRE ".*src=\"(.+?)\".*" "$1" }}">
5+
{{ end }}
6+
{{- else -}}
7+
{{- with resources.Get "images/kubernetes-horizontal-color.png" -}}
8+
{{- with resources.Copy "images/kubernetes-open-graph.png" . -}}
9+
<meta property="og:image" content="{{ .RelPermalink }}">
10+
{{- else -}}
11+
{{- warnf "No image. Boo." -}}
12+
{{- end -}}
13+
{{- end -}}
14+
{{- end -}}
15+
16+
<link rel="manifest" href="/manifest.webmanifest">
17+
{{ range .Translations -}}
18+
<link rel="alternate" hreflang="{{ .Language.Lang }}" href="{{ .Permalink }}">
19+
{{ end -}}
20+
<script type="application/ld+json">
21+
{
22+
"@context": "https://schema.org",
23+
"@type": "Organization",
24+
"url": "https://kubernetes.io",
25+
"logo": "https://kubernetes.io/images/favicon.png",
26+
{{- if not .Site.Params.deprecated }}
27+
"potentialAction": {
28+
"@type": "SearchAction",
29+
"target": {{ printf "%s%s" ("search/" | absURL) "?q={search_term_string}" }},
30+
"query-input": "required name=search_term_string"
31+
}
32+
{{ end }}
33+
}
34+
</script>
35+
36+
<meta name="theme-color" content="#326ce5">
37+
138
<link rel="manifest" href="/manifest.webmanifest">
239

340
{{- if or (.HasShortcode "table") (.HasShortcode "feature-gate-table") -}}
@@ -55,3 +92,9 @@
5592
{{- if or (.HasShortcode "code_sample") (.HasShortcode "code") (.HasShortcode "codenew") -}}
5693
<link rel="stylesheet" href="/css/toastr-2.1.4.min.css">
5794
{{- end -}}
95+
96+
{{- if eq (lower .Params.cid) "community" -}}
97+
<script defer src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
98+
{{- end -}}
99+
{{ with .Params.js }}{{ range (split . ",") }}<script src="{{ (trim . " ") | relURL }}"></script><!-- custom js added -->
100+
{{ end }}{{ else }}<!-- no custom js detected -->{{ end }}

0 commit comments

Comments
 (0)