diff options
| author | Serghei Iakovlev <egrep@protonmail.ch> | 2022-05-16 00:33:53 +0200 |
|---|---|---|
| committer | Serghei Iakovlev <egrep@protonmail.ch> | 2022-05-16 00:33:53 +0200 |
| commit | cfc3f2c8c067d47505e64b1445c4692316fd4eb6 (patch) | |
| tree | 0f88f5e4ffb31b9b7484865945c2612d7b684069 /layouts/partials | |
| parent | 046753f526fb3247855886d229768076667fd1a1 (diff) | |
| download | gohugo-theme-ed-cfc3f2c8c067d47505e64b1445c4692316fd4eb6.tar.gz | |
Introduce description partial
Diffstat (limited to 'layouts/partials')
| -rw-r--r-- | layouts/partials/description.html | 15 | ||||
| -rw-r--r-- | layouts/partials/head.html | 7 | ||||
| -rw-r--r-- | layouts/partials/templates/opengraph.html | 2 |
3 files changed, 17 insertions, 7 deletions
diff --git a/layouts/partials/description.html b/layouts/partials/description.html new file mode 100644 index 0000000..e63c0d9 --- /dev/null +++ b/layouts/partials/description.html @@ -0,0 +1,15 @@ +{{- $description := "" -}} + +{{- if .IsHome -}} + {{- $description = site.Params.Description -}} +{{- else -}} + {{- if and (.Params.Description) (ne .Params.Description "") -}} + {{- $description = print .Params.Description -}} + {{- else if and (.Params.Summary ) (ne .Params.Summary "") -}} + {{- $description = print .Params.Summary -}} + {{- else -}} + {{- $description = print .Summary -}} + {{- end -}} +{{- end -}} + +{{- $description | plainify | safeHTML | chomp | truncate 180 -}} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index abb4cbe..478410a 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -1,10 +1,5 @@ {{/* */}} <head> - {{- $description := print .Params.Description -}} - {{- if or .IsHome (eq .Params.Description "") (not .Params.Description) -}} - {{ $description = site.Params.Description }} - {{- end -}} - <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width,initial-scale=1.0,shrink-to-fit=no"> @@ -13,7 +8,7 @@ <link type="text/plain" rel="author" href="{{ "humans.txt" | absURL }}"> <title>{{ block "title" . }}{{ if .IsHome }}{{ site.Title }}{{ else }}{{ with .Params.Title }}{{ . }} - {{ end }}{{ site.Title }}{{ end }}{{ end }}</title> - <meta name="description" content="{{ $description }}"> + <meta name="description" content="{{ (partial "description.html" . ) }}"> <meta name="author" content="{{ (partial "author.html" . ) }}"> {{ hugo.Generator }} diff --git a/layouts/partials/templates/opengraph.html b/layouts/partials/templates/opengraph.html index c94fd68..3b9fb36 100644 --- a/layouts/partials/templates/opengraph.html +++ b/layouts/partials/templates/opengraph.html @@ -1,6 +1,6 @@ <!-- Open Graph metadata --> <meta property="og:title" content="{{ .Title }}"> - <meta property="og:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ replaceRE "\n" " " (.Summary | truncate 170) }}{{ else }}{{ with site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}"> + <meta property="og:description" content="{{ (partial "description.html" . ) }}"> <meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}"> <meta property="og:url" content="{{ .Permalink }}"> {{- if .Params.cover.image -}} |
