refactor(head/opengraph): split code into modules

This commit is contained in:
Jimmy Cai 2020-09-11 21:55:15 +02:00
parent 03f91c36b2
commit 5f7e818b92
No known key found for this signature in database
GPG Key ID: 3EA408E527F37B18
5 changed files with 17 additions and 10 deletions

View File

@ -40,6 +40,7 @@ DefaultContentLanguage = "en" # Theme i18n support
[params.opengraph]
[params.opengraph.twitter]
site = ""
card = "summary_large_image"
[params.defaultImage]
[params.defaultImage.article]
enabled = false

View File

@ -9,7 +9,7 @@
{{ partial "head/style.html" . }}
{{ partial "head/script.html" . }}
{{ partial "head/opengraph.html" . }}
{{ partial "head/opengraph/include.html" . }}
{{ range .AlternativeOutputFormats -}}
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | safeURL }}">

View File

@ -0,0 +1,2 @@
{{ partial "head/opengraph/provider/base" . }}
{{ partial "head/opengraph/provider/twitter" . }}

View File

@ -10,12 +10,6 @@
{{- end -}}
'>
{{ with .Site.Params.opengraph.twitter.site }}
<meta name="twitter:site" content="{{ . }}">
{{ end }}
<meta name="twitter:title" content="{{ partial "data/title" . }}">
<meta name="twitter:description" content="{{ chomp (partial "data/description" . | plainify ) }}">
{{- with .Params.locale -}}
<meta property='og:locale' content='{{ . }}'>
{{- end -}}
@ -42,7 +36,5 @@
{{ $image := partial "helper/image" (dict "Context" . "Type" "opengraph") }}
{{- if $image.exists -}}
<meta name="twitter:card" content="summary_large_image">
<meta property='og:image' content='{{ absURL $image.permalink }}' />
<meta name="twitter:image" content='{{ absURL $image.permalink }}' />
{{- end -}}

View File

@ -0,0 +1,12 @@
{{- with .Site.Params.opengraph.twitter.site -}}
<meta name="twitter:site" content="{{ . }}">
{{- end -}}
<meta name="twitter:title" content="{{ partial "data/title" . }}">
<meta name="twitter:description" content="{{ chomp (partial "data/description" . | plainify ) }}">
{{- $image := partial "helper/image" (dict "Context" . "Type" "opengraph") -}}
{{- if $image.exists -}}
<meta name="twitter:card" content="{{ .Site.Params.opengraph.twitter.card }}">
<meta name="twitter:image" content='{{ absURL $image.permalink }}' />
{{- end -}}