summaryrefslogtreecommitdiffstats
path: root/layouts
diff options
context:
space:
mode:
authoramzrk22020-12-27 13:12:06 +0800
committeramzrk22020-12-27 13:12:06 +0800
commit9686bf9ce438794d2bd1002bedd89e75ca63cb67 (patch)
treed8e9d5bef35d93d9919b4624d92e15e40853b42a /layouts
parent5c307e15cae258cce5d271c46d5d64b8ea26dae0 (diff)
downloadhugo-theme-fuji-9686bf9ce438794d2bd1002bedd89e75ca63cb67.tar.gz
hugo-theme-fuji-9686bf9ce438794d2bd1002bedd89e75ca63cb67.tar.bz2
hugo-theme-fuji-9686bf9ce438794d2bd1002bedd89e75ca63cb67.zip
fix: og image absolute link
Diffstat (limited to 'layouts')
-rw-r--r--layouts/partials/head.html4
-rw-r--r--layouts/partials/opengraph.html45
2 files changed, 47 insertions, 2 deletions
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 993e1a9..f4ebe64 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -26,8 +26,8 @@
{{ if .Params.tags }}
<meta name="keywords" content="{{ delimit .Params.tags ", " }}" />
{{ end }}
-{{ template "_internal/opengraph.html" . }}
-{{ template "_internal/twitter_cards.html" . }}
+<!-- og -->
+{{ partial "opengraph.html" . }}
<!-- dep -->
{{ partial "styles.html" . }}
{{ $options := (dict "targetPath" "assets/css/fuji.min.css" "outputStyle" "compressed") }}
diff --git a/layouts/partials/opengraph.html b/layouts/partials/opengraph.html
new file mode 100644
index 0000000..1437837
--- /dev/null
+++ b/layouts/partials/opengraph.html
@@ -0,0 +1,45 @@
+<meta property="og:title" content="{{ .Title }}" />
+<meta name="twitter:title" content="{{ .Title }}" />
+<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}" />
+<meta property="og:url" content="{{ .Permalink }}" />
+
+{{- if .Description -}}
+<meta property="og:description" content="{{ .Description }}" />
+<meta name="twitter:description" content="{{ .Description }}" />
+{{- else if .Params.description -}}
+<meta property="og:description" content="{{ .Params.description }}" />
+<meta name="twitter:description" content="{{ .Params.description }}" />
+{{- else -}}
+{{- if .IsPage -}}
+<meta property="og:description" content="{{ .Summary }}" />
+<meta name="twitter:description" content="{{ .Summary }}" />
+{{- end -}}
+{{- end -}}
+
+{{- if .Params.image -}}
+<meta property="og:image" content="{{ .Params.image | absURL }}" />
+<meta name="twitter:card" content="summary_large_image" />
+<meta name="twitter:image" content="{{ .Params.image | absURL }}" />
+{{- else if .Site.Params.og -}}
+<meta property="og:image" content="{{ .Site.Params.og | absURL }}" />
+<meta name="twitter:card" content="summary_large_image" />
+<meta name="twitter:image" content="{{ .Site.Params.og | absURL }}" />
+{{- else -}}
+<meta name="twitter:card" content="summary" />
+{{- end -}}
+
+{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
+{{- if .IsPage -}}
+{{- if not .PublishDate.IsZero -}}
+<meta property="article:published_time" {{ .PublishDate.Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />
+{{- else if not .Date.IsZero -}}
+<meta property="article:published_time" {{ .Date.Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />
+{{- end -}}
+{{- if not .Lastmod.IsZero -}}
+<meta property="article:modified_time" {{ .Lastmod.Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />
+{{- end -}}
+{{- else -}}
+{{- if not .Date.IsZero -}}
+<meta property="og:updated_time" {{ .Lastmod.Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />
+{{- end -}}
+{{- end -}}