diff options
author | somratpro <abdulmonnafsomrat@gmail.com> | 2021-04-29 06:13:39 +0300 |
---|---|---|
committer | somratpro <abdulmonnafsomrat@gmail.com> | 2021-04-29 06:13:39 +0300 |
commit | 4685e0da5808cb3cc8a63fc78774b840883a4e32 (patch) | |
tree | 19558ff1f04fa8e089598ac0f0a8a5a7fd1f3492 | |
parent | e45d6108ea93c436892aa81a5f20e682385f7c30 (diff) |
added meta OG and Twitter data
-rw-r--r-- | exampleSite/config.toml | 5 | ||||
-rw-r--r-- | layouts/partials/head.html | 29 |
2 files changed, 34 insertions, 0 deletions
diff --git a/exampleSite/config.toml b/exampleSite/config.toml index b36d169..0d284a2 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -22,6 +22,11 @@ logo = "" logo_white = "" # when logo is empty, it will shown your site title +# OpenGraph / Twitter Card metadata +description = "This is meta description" +author = "Themefisher" +image = "images/logo.png" # this image will be used as fallback if a page has no image of its own + # customize color primary_color = "#02007e" body_color = "#f9f9f9" diff --git a/layouts/partials/head.html b/layouts/partials/head.html index c7b8ada..e3693d7 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -57,4 +57,33 @@ {{ "<!-- create /layouts/partials/overrides/header.html in your own theme or root directory to add your custom content here -->" | safeHTML }} {{ end }} + +<!-- Open Graph image and Twitter Card metadata --> +{{ $image_path := .Params.image | default site.Params.image }} +{{ $image_path_local := printf "static/%s" $image_path }} +{{ $image_ext := trim (path.Ext $image_path | lower) "." }} +{{ if fileExists $image_path_local }} + <meta property="og:image" content="{{ $image_path | absURL }}" /> + {{ if ne $image_ext "svg" }} + {{ with (imageConfig $image_path_local) }} + {{ if (and (gt .Width 144) (gt .Height 144)) }} + <meta name="twitter:image" content="{{ $image_path | absURL }}"/> + <meta name="twitter:card" content="summary{{ if (and (gt .Width 300) (gt .Height 157) (not (eq .Width .Height))) }}_large_image{{ end }}"> + {{ end }} + <meta property="og:image:width" content="{{ .Width }}"> + <meta property="og:image:height" content="{{ .Height }}"> + {{ end }} + {{ end }} + <meta property="og:image:type" content="image/{{ if eq $image_ext `svg` }}svg+xml{{ else }}{{ replaceRE `^jpg$` `jpeg` $image_ext }}{{ end }}"> +{{ end }} +<meta name="twitter:title" content="{{ .Title }}"/> +<meta name="twitter:description" content="{{ with .Description }}{{ . }}{{ else }}{{ if .IsPage }}{{ .Summary }}{{ else }}{{ with site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}"/> +{{ with site.Social.twitter }}<meta name="twitter:site" content="@{{ . }}"/>{{ end }} +{{ range site.Authors }} + {{ with .twitter }}<meta name="twitter:creator" content="@{{ . }}"/>{{ end }} +{{ end }} + +{{ template "_internal/opengraph.html" . }} +{{ template "_internal/twitter_cards.html" . }} + </head> |