reafctor(head): rewrite description.html function

This commit is contained in:
Jimmy Cai 2020-09-11 23:00:19 +02:00
parent 6f5ee1bbdb
commit 5265af0b3b
No known key found for this signature in database
GPG key ID: 3EA408E527F37B18
4 changed files with 28 additions and 18 deletions

View file

@ -1,11 +1,12 @@
{{- with .Description -}}
{{- . -}}
{{- else -}}
{{- if .IsPage -}}
{{- .Summary -}}
{{- else -}}
{{- with .Site.Params.subtitle -}}
{{- . -}}
{{- end -}}
{{- end -}}
{{- end -}}
<!-- Use site subtitle by default -->
{{ $description := .Site.Params.subtitle }}
{{ if .Description }}
<!-- Page description exists -->
{{ $description = .Description }}
{{ else if .IsPage }}
<!-- Use page summary -->
{{ $description = .Summary }}
{{ end }}
{{ return ($description | plainify)}}

View file

@ -1,10 +1,13 @@
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<meta name='description' content='{{ chomp (partial "data/description" . | plainify ) }}'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
{{- $description := partial "data/description" . -}}
<meta name='description' content='{{ $description }}'>
{{- $title := partial "data/title" . -}}
<title>{{ $title }}</title>
<title>{{ $title }}</title>
<link rel='canonical' href='{{ .Permalink }}'>
{{- partial "head/style.html" . -}}

View file

@ -1,5 +1,8 @@
<meta property='og:title' content='{{ partial "data/title" . }}'>
<meta property='og:description' content='{{ chomp (partial "data/description" . | plainify ) }}'>
{{- $title := partial "data/title" . -}}
{{- $description := partial "data/description" . -}}
<meta property='og:title' content='{{ $title }}'>
<meta property='og:description' content='{{ $description }}'>
<meta property='og:url' content='{{ .Permalink }}'>
<meta property='og:site_name' content='{{ .Site.Title }}'>
<meta property='og:type' content='

View file

@ -2,8 +2,11 @@
<meta name="twitter:site" content="{{ . }}">
{{- end -}}
<meta name="twitter:title" content="{{ partial "data/title" . }}">
<meta name="twitter:description" content="{{ chomp (partial "data/description" . | plainify ) }}">
{{- $title := partial "data/title" . -}}
{{- $description := partial "data/description" . -}}
<meta name="twitter:title" content="{{ $title }}">
<meta name="twitter:description" content="{{ $description }}">
{{- $image := partial "helper/image" (dict "Context" . "Type" "opengraph") -}}
{{- if $image.exists -}}