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

github.com/kc0bfv/autophugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl <kc0bfv@gmail.com>2021-09-13 06:02:00 +0300
committerKarl <kc0bfv@gmail.com>2021-09-13 06:02:00 +0300
commit414ea49799f36226333691d8666b3518a9a8c48c (patch)
treed60355dfafaac52fc0e32343298b00dcf9b04f1a /layouts
parent4fabd15f69673bcfbb83029ecd5eef816c671de4 (diff)
Implement twitter and og change with new template
Refactor out the albumthumb selection so we can reuse it to select images for opengraph and twitter_cards, then modify the internal opengraph and twitter_card templates so they reflect the same design decisions in the head template and so they use the right image (some code is duplicative still but...)
Diffstat (limited to 'layouts')
-rw-r--r--layouts/partials/head.html17
-rw-r--r--layouts/partials/opengraph_twittercard.html19
-rw-r--r--layouts/partials/scratch_set_retalbumthumb.html24
-rw-r--r--layouts/partials/sect_and_img_content.html18
4 files changed, 52 insertions, 26 deletions
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 0a3cdc7..882cd91 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -9,17 +9,12 @@
<link rel="icon" href="{{ .Site.Params.favicon | relURL }}">
<link rel="shortcut icon" href="{{ .Site.Params.favicon | relURL }}">
-{{- template "_internal/opengraph.html" . }}
-{{- template "_internal/twitter_cards.html" . }}
-{{- if not .Params.images }}
- {{- with .Params.albumthumb }}
- {{- /* Manually add preview from albumthumb if internal tmplate misses it */}}
- {{- $image := resources.Get . }}
- <meta property="og:image" content="{{ $image.Permalink }}">
- <meta name="twitter:card" content="summary_large_image">
- <meta name="twitter:image" content="{{ $image.Permalink }}">
- {{- end }}
-{{- end }}
+{{- partial "scratch_set_retalbumthumb.html" . }}
+{{- /* Note that the Scratch below must come from . context, not $ */}}
+{{- .Scratch.Set "image" (.Scratch.Get "retalbumthumb") }}
+
+{{- partial "opengraph_twittercard.html" . }}
+
<meta name="robots" content="index,follow">
<meta name="referrer" content="origin-when-cross-origin">
{{ with .Site.Params.googlesiteverification }}<meta name="google-site-verification" content="{{ . }}">{{ end }}
diff --git a/layouts/partials/opengraph_twittercard.html b/layouts/partials/opengraph_twittercard.html
new file mode 100644
index 0000000..e401f21
--- /dev/null
+++ b/layouts/partials/opengraph_twittercard.html
@@ -0,0 +1,19 @@
+{{- $description := $.Param "description" }}
+
+<meta name="twitter:card" content="summary_large_image"/>
+<meta name="twitter:image" content="{{ (.Scratch.Get "image").Permalink }}"/>
+<meta name="twitter:title" content="{{ with .Title }}{{ . }} - {{ end }}{{ .Site.Title }}"/>
+{{- with $description }}<meta name="twitter:description" content="{{ . }}">{{ end }}
+{{- with .Site.Social.twitter }}<meta name="twitter:site" content="@{{ . }}"/>{{- end }}
+
+
+<meta property="og:title" content="{{ with .Title }}{{ . }} - {{ end }}{{ .Site.Title }}"/>
+{{- with $description }}<meta property="og:description" content="{{ . }}">{{ end }}
+<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}" />
+<meta property="og:url" content="{{ .Permalink }}" />
+<meta property="og:image" content="{{ (.Scratch.Get "image").Permalink }}"/>
+{{- with .Params.locale }}<meta property="og:locale" content="{{ . }}" />{{ end }}
+{{- with .Site.Title }}<meta property="og:site_name" content="{{ . }}" />{{ end }}
+
+{{- /* Facebook Page Admin ID for Domain Insights */}}
+{{- with .Site.Social.facebook_admin }}<meta property="fb:admins" content="{{ . }}" />{{ end }}
diff --git a/layouts/partials/scratch_set_retalbumthumb.html b/layouts/partials/scratch_set_retalbumthumb.html
new file mode 100644
index 0000000..c718581
--- /dev/null
+++ b/layouts/partials/scratch_set_retalbumthumb.html
@@ -0,0 +1,24 @@
+{{- /*
+ Sets retalbumthumb in .Scratch to the correct albumthumb.
+ PLEASE NOTE: partials can only get local "dot" . context, they
+ do not get the global $ context. Therefore, you must get the returned
+ scratch data from the . context, not from $.
+
+ Requires . to be set to the right section.
+ */}}
+
+{{- .Scratch.Delete "retalbumthumb" }}
+
+{{- /* If no albumthumb is set, get the first image*/}}
+{{- if or (not (isset .Params "albumthumb")) (eq .Params.albumthumb "") }}
+ {{- $imgglob := printf "%s" (path.Join .File.Dir "**") }}
+ {{- $imageresources := where (resources.Match $imgglob) "ResourceType" "image" }}
+ {{- .Scratch.Set "retalbumthumb" (index $imageresources 0) }}
+{{- end }}
+
+{{- /* Otherwise get the albumthumb*/}}
+{{- with .Params.albumthumb }}
+ {{- $image := resources.Get . }}
+ {{- /* The $ here with Scratch means the context outside the with */}}
+ {{- $.Scratch.Set "retalbumthumb" $image }}
+{{- end }}
diff --git a/layouts/partials/sect_and_img_content.html b/layouts/partials/sect_and_img_content.html
index 52d385a..4583a3d 100644
--- a/layouts/partials/sect_and_img_content.html
+++ b/layouts/partials/sect_and_img_content.html
@@ -19,22 +19,10 @@
{{- $title := .Title }}
{{- $link := .RelPermalink }}
- {{- $.Scratch.Delete "image" }}
+ {{- partial "scratch_set_retalbumthumb.html" . }}
+ {{- /* Note that the Scratch below must come from . context, not $ */}}
+ {{- $image := .Scratch.Get "retalbumthumb" }}
- {{- /* If no albumthumb is set, get the first image*/}}
- {{- if or (not (isset .Params "albumthumb")) (eq .Params.albumthumb "") }}
- {{- $imgglob := printf "%s" (path.Join .File.Dir "**") }}
- {{- $imageresources := where (resources.Match $imgglob) "ResourceType" "image" }}
- {{- $.Scratch.Set "image" (index $imageresources 0) }}
- {{- end }}
-
- {{- /* Otherwise get the albumthumb*/}}
- {{- with .Params.albumthumb }}
- {{- $image := resources.Get . }}
- {{- $.Scratch.Set "image" $image }}
- {{- end }}
-
- {{- $image := $.Scratch.Get "image" }}
{{- if not $image }}
{{- errorf (printf "When processing '%s', no thumbnail image found for: %s" $.Page.File.Path $title) }}
{{- else }}