Skip to content

Commit

Permalink
Merge pull request #48350 from sftim/20241015_tidy_page_head
Browse files Browse the repository at this point in the history
Tidy <head> for pages
  • Loading branch information
k8s-ci-robot authored Jan 27, 2025
2 parents da0b312 + ee50a91 commit af0077f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 74 deletions.
112 changes: 38 additions & 74 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{{- $isBlogPost := eq .Section "blog" }}
{{- $ogType := cond (.IsHome) "website" "article" }}
{{/* Adapted from Docsy; changes are to Google Analytics */}}
{{/* OK to remove once using a modern enough Docsy (eg 0.11.0 or later) */}}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
{{ hugo.Generator }}
{{ range .AlternativeOutputFormats -}}
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | safeURL }}">
{{ end -}}

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

<!-- alternative translations -->
{{ range .Translations -}}
<link rel="alternate" hreflang="{{ .Language.Lang }}" href="{{ .Permalink }}">
{{ end -}}

<!-- Docsy head.html begins here -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
{{ hugo.Generator }}
{{ range .AlternativeOutputFormats -}}
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | safeURL }}">
{{ end -}}
{{ partialCached "favicons.html" . }}
<title>{{ if .IsHome }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{ . }} | {{ end }}{{ .Site.Title }}{{ end }}</title>
{{- template "_internal/opengraph.html" . -}}
{{- template "_internal/schema.html" . -}}
{{- template "_internal/twitter_cards.html" . -}}
{{- if hugo.IsProduction -}}
{{ template "_internal/google_analytics.html" . }}
{{ end }}
{{ partialCached "head-css.html" . "asdf" }}
{{ if and (.Site.Params.offlineSearch) (not .Site.Params.gcs_engine_id) }}
<script src="https://unpkg.com/[email protected]/lunr.js"></script>
<script src="/js/offline-search.js"></script>
{{end}}

<!-- Docsy head.html ends here -->

<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "https://kubernetes.io",
"logo": "https://kubernetes.io/images/favicon.png",
{{- if not .Site.Params.deprecated }}
"potentialAction": {
"@type": "SearchAction",
"target": {{ printf "%s%s" ("search/" | absURL) "?q={search_term_string}" }},
"query-input": "required name=search_term_string"
}
{{ end }}
}
</script>
<meta name="theme-color" content="#326ce5">
{{ partial "css.html" . }}
<!-- Content for social media sharing previews -->
<!-- Facebook uses the og: stuff, while Twitter and others use twitter: -->
<title>
{{- if .IsHome -}}
{{ .Site.Title -}}
{{ else -}}
{{ with .Title }}{{ . }} | {{ end -}}
{{ .Site.Title -}}
{{ end -}}
</title>
<meta name="description" content="{{ template "partials/page-description.html" . }}">
<meta property="og:description" content="{{ template "partials/page-description.html" . }}">
<meta name="twitter:description" content="{{ template "partials/page-description.html" . }}">
<meta property="og:url" content="{{ .Permalink }}">
<meta property="og:title" content="{{ if .Params.title }}{{ .Title }}{{ else }}{{ .Summary | truncate 10 }}{{ end }}">
<meta name="twitter:title" content="{{ if .Params.title }}{{ .Title }}{{ else }}{{ .Summary | truncate 10 }}{{ end }}">
<meta name="twitter:image" content="https://kubernetes.io/images/favicon.png" />
<!-- Alt text for the site image -->
<meta name="twitter:image:alt" content="{{ site.Title }}">
{{ if $isBlogPost }}
{{ with findRE "<img.*?>" .Content 1 }}
<meta property="og:image" content="{{ index . 0 | replaceRE ".*src=\"(.+?)\".*" "$1" }}">
{{ end }}
{{ else }}
<meta property="og:image" content="{{ "/images/kubernetes-horizontal-color.png" | relURL }}">
{{ end }}
<meta property="og:type" content="{{ $ogType }}">
{{ template "_internal/opengraph.html" . -}}
{{ template "_internal/schema.html" . -}}
{{ template "_internal/twitter_cards.html" . -}}
{{ partialCached "head-css.html" . "asdf" -}}
<script
src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha384-vtXRMe3mGCbOeY7l30aIg8H9p3GdeSe4IFlP6G8JMa7o7lXvnz3GFKzPxzJdPfGK"
crossorigin="anonymous"></script>
{{ if .Site.Params.offlineSearch -}}
<script defer
src="https://unpkg.com/[email protected]/lunr.min.js"
integrity="sha384-203J0SNzyqHby3iU6hzvzltrWi/M41wOP5Gu+BiJMz5nwKykbkUx8Kp7iti0Lpli"
crossorigin="anonymous"></script>
{{ end -}}

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

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

{{/* make sure that head-end hook comes last */}}
{{ partial "hooks/head-end.html" . }}
{{/* To comply with GDPR, cookie consent scripts places in head-end must execute before Google Analytics is enabled */ -}}
{{ if hugo.IsProduction -}}
{{ template "_internal/google_analytics.html" . }}
{{ end -}}
43 changes: 43 additions & 0 deletions layouts/partials/hooks/head-end.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
{{/* reference page-specific open graph image */}}
{{- if ( eq .Section "blog" ) -}}
{{ with findRE "<img.*?>" .Content 1 }}
<meta property="og:image" content="{{ index . 0 | replaceRE ".*src=\"(.+?)\".*" "$1" }}">
{{ end }}
{{- else -}}
{{- with resources.Get "images/kubernetes-horizontal-color.png" -}}
{{- with resources.Copy "images/kubernetes-open-graph.png" . -}}
<meta property="og:image" content="{{ .RelPermalink }}">
{{- else -}}
{{- warnf "No image. Boo." -}}
{{- end -}}
{{- end -}}
{{- end -}}

<link rel="manifest" href="/manifest.webmanifest">
{{ range .Translations -}}
<link rel="alternate" hreflang="{{ .Language.Lang }}" href="{{ .Permalink }}">
{{ end -}}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "https://kubernetes.io",
"logo": "https://kubernetes.io/images/favicon.png",
{{- if not .Site.Params.deprecated }}
"potentialAction": {
"@type": "SearchAction",
"target": {{ printf "%s%s" ("search/" | absURL) "?q={search_term_string}" }},
"query-input": "required name=search_term_string"
}
{{ end }}
}
</script>

<meta name="theme-color" content="#326ce5">

<link rel="manifest" href="/manifest.webmanifest">

{{- if or (.HasShortcode "table") (.HasShortcode "feature-gate-table") -}}
Expand Down Expand Up @@ -55,3 +92,9 @@
{{- if or (.HasShortcode "code_sample") (.HasShortcode "code") (.HasShortcode "codenew") -}}
<link rel="stylesheet" href="/css/toastr-2.1.4.min.css">
{{- end -}}

{{- if eq (lower .Params.cid) "community" -}}
<script defer src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
{{- end -}}
{{ with .Params.js }}{{ range (split . ",") }}<script src="{{ (trim . " ") | relURL }}"></script><!-- custom js added -->
{{ end }}{{ else }}<!-- no custom js detected -->{{ end }}

0 comments on commit af0077f

Please sign in to comment.