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

github.com/devcows/hugo-universal-theme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalim B <salim@posteo.de>2019-10-30 01:03:54 +0300
committerGuillermo Guerrero Ibarra <wolf.fox1985@gmail.com>2019-10-30 01:03:54 +0300
commitab8025799d63ff437c2d5fad92e544b1ea4721c6 (patch)
treedd08ec9ba69829a33261368f6a1f9e6179e2a310
parent25bbf4378fa039ca5fe7b6a24e0acee6a687f260 (diff)
meta tags: check for image file existence and improve keywords generation (#239)1.0.2
* meta tags: check for image file existence * improve 'keywords' meta tag generation * minor code improvement * fix build error when no keywords could be found * fix post image file existence check and fix build error when no post image could be found * fix initialization
-rw-r--r--layouts/partials/head.html16
1 files changed, 13 insertions, 3 deletions
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 1efc640..298c8bc 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -6,7 +6,12 @@
{{ $title_plain := .Title | markdownify | plainify }}
<title>{{ $title_plain }}</title>
<meta name="author" content="{{ .Param "author" }}" />
- <meta name="keywords" content="{{ with .Keywords }}{{ delimit . ", " }}{{ else }}{{ delimit .Site.Params.defaultKeywords ", " }}{{ end }}">
+ {{ $keywords := .Site.Params.defaultKeywords | default (slice "" | first 0) }}
+ {{ if isset .Params "tags" }}{{ range .Params.tags }}{{ $keywords = $keywords | append . }}{{ end }}{{ end }}
+ {{ if isset .Params "keywords" }}{{ range .Params.keywords }}{{ $keywords = $keywords | append . }}{{ end }}{{ end }}
+ {{ if gt (len $keywords) 0 }}
+ <meta name="keywords" content="{{ delimit (uniq $keywords) ", " }}">
+ {{ end }}
{{ $description_plain := default .Site.Params.defaultDescription .Description | markdownify | plainify }}
<meta name="description" content="{{ $description_plain }}">
@@ -54,7 +59,9 @@
<!-- Facebook OpenGraph tags -->
{{ $is_blog := and (eq .Type "blog") (eq .Kind "page") }}
{{ $has_image := isset .Params "banner" }}
- {{ $image := cond $has_image .Params.banner .Site.Params.default_sharing_image }}
+ {{ $image := cond $has_image .Params.banner (.Site.Params.default_sharing_image | default "img/sharing-default.png") }}
+ {{ $is_valid_image := print "static/" $image | fileExists }}
+ {{ if $is_valid_image }}
{{ $image_ext := path.Ext $image }}
<meta property="og:locale" content="{{ replace .Site.LanguageCode "-" "_" }}">
<meta property="og:site_name" content="{{ .Site.Title }}">
@@ -70,6 +77,7 @@
<meta property="og:image:width" content="{{ .Width }}">
<meta property="og:image:height" content="{{ .Height }}">
{{ end }}
+ {{ end }}
{{ with .Lastmod }}<meta property="og:updated_time" content="{{ .Format "2006-01-02T15:04:05Z0700" }}">{{ end }}
{{ if $is_blog }}
{{ with .Param "facebook_site" }}<meta property="article:publisher" content="https://www.facebook.com/{{ . }}/">{{ end }}
@@ -83,10 +91,12 @@
{{ end }}
<!-- Twitter Card meta tags -->
- <meta name="twitter:card" content="summary{{ if and $is_blog $has_image }}_large_image{{ end }}">
+ <meta name="twitter:card" content="summary{{ if (and $is_blog (and $has_image $is_valid_image)) }}_large_image{{ end }}">
{{ with .Param "twitter_site" }}<meta name="twitter:site" content="@{{ . }}">{{ end }}
<meta name="twitter:title" content="{{ $title_plain | truncate 70 }}">
+ {{ if $is_valid_image }}
<meta name="twitter:image" content="{{ $image | absURL }}">
+ {{ end }}
<meta name="twitter:description" content="{{ $description_plain | truncate 200 }}">
{{ with .Param "twitter_author" }}<meta name="twitter:creator" content="@{{ . }}">{{ end }}