Skip to content

Commit

Permalink
Add og:image meta tag to non-blog pages (kubernetes#10213)
Browse files Browse the repository at this point in the history
* Add og:image meta tag to non-blog pages

* Fix other minor OpenGraph issues
  • Loading branch information
lucperkins authored and k8s-ci-robot committed Oct 4, 2018
1 parent 11e937b commit 48aa30d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{- $isBlogPost := eq .Section "blog" }}
{{- $ogType := cond (.IsHome) "website" "article" }}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-36037335-10"></script>
<script>
Expand All @@ -14,19 +16,22 @@
{{ partial "css.html" . }}
<!-- Content for social media sharing previews -->
<!-- Facebook uses the og: stuff, while Twitter and others use twitter: -->
<meta name="description" content="{{ if .Params.description }}{{ .Params.description }}{{ else }}{{ .Summary }}{{ end }}" />
<meta property="og:description" content="{{ if .Params.description }}{{ .Params.description }}{{ else }}{{ .Summary }}{{ end }}" />
<meta property="twitter:description" content="{{ if .Params.description }}{{ .Params.description }}{{ else }}{{ .Summary }}{{ end }}" />
<meta property="og:url" content="{{ .Permalink }}" />
<meta name="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="description" content="{{ if .Params.description }}{{ .Params.description }}{{ else }}{{ .Summary }}{{ end }}">
<meta property="og:description" content="{{ if .Params.description }}{{ .Params.description }}{{ else }}{{ .Summary }}{{ end }}">
<meta name="twitter:description" content="{{ if .Params.description }}{{ .Params.description }}{{ else }}{{ .Summary }}{{ end }}">
<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 }}">
<!-- Alt text for the site image -->
<meta name="twitter:image:alt" content="{{ .Site.Title }}">
{{ if eq .Section "blog" }}
{{ if $isBlogPost }}
{{ with findRE "<img.*?>" .Content 1 }}
<meta property="og:image" content="{{ index . 0 | replaceRE ".*src=\"(.+?)\".*" "$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 }}">
<script src="{{ "js/anchor-4.1.1.min.js" | relURL }}"></script>
<script src="{{ "js/jquery-3.2.1.min.js" | relURL }}"></script>
<script src="{{ "js/jquery-ui-1.12.1.min.js" | relURL }}"></script>
Expand Down
Binary file added static/images/kubernetes-horizontal-color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 48aa30d

Please sign in to comment.