Improve description meta tag.

This commit is contained in:
Fredrik Jonsson 2025-01-20 10:58:22 +01:00
commit 1994fe787a
2 changed files with 10 additions and 4 deletions

View file

@ -13,11 +13,13 @@
"datePublished": {{ .Date.Format "2006-01-02T15:04:05Z07:00" }}, "datePublished": {{ .Date.Format "2006-01-02T15:04:05Z07:00" }},
"dateModified": {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}, "dateModified": {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }},
"url" : {{ .Permalink }}, "url" : {{ .Permalink }},
{{ with (.Description | default (replaceRE "\n" " " (.Plain | truncate 170))) -}} {{ if .IsHome -}}
"description": {{ . }}, {{ with $.Param "description" }}"description": {{ . }},{{ end }}
{{ else -}}
{{ with .Description }}"description": {{ . }},{{ end }}
{{ end -}} {{ end -}}
{{ with .Params.tags -}} {{ with .Params.tags -}}
"keywords": {{ . }}, "keywords": {{ delimit . " " }},
{{ end -}} {{ end -}}
{{ else -}} {{ else -}}
"@type": "WebPage", "@type": "WebPage",

View file

@ -2,7 +2,11 @@
<link rel="{{ .Rel }}" {{ printf "type=%q" .MediaType.Type | safeHTMLAttr }} title="{{ .Name }}" href="{{ .Permalink | safeURL }}"> <link rel="{{ .Rel }}" {{ printf "type=%q" .MediaType.Type | safeHTMLAttr }} title="{{ .Name }}" href="{{ .Permalink | safeURL }}">
{{ end -}} {{ end -}}
<meta name="view-transition" content="same-origin"> <meta name="view-transition" content="same-origin">
<meta name="description" content="{{ with (.Description | default (replaceRE "\n" " " (.Plain | truncate 170))) }}{{ . }}{{ end }}"> {{ if .IsHome -}}
{{ with $.Param "description" }}<meta name="description" content="{{ . }}">{{ end }}
{{ else -}}
{{ with .Description }}<meta name="description" content="{{ . }}">{{ end }}
{{ end -}}
<meta name="created" {{ printf "content=%q" (.Date.Format "2006-01-02T15:04:05-0700") | safeHTMLAttr }}> <meta name="created" {{ printf "content=%q" (.Date.Format "2006-01-02T15:04:05-0700") | safeHTMLAttr }}>
<meta name="modified" {{ printf "content=%q" (.Lastmod.Format "2006-01-02T15:04:05-0700") | safeHTMLAttr }}> <meta name="modified" {{ printf "content=%q" (.Lastmod.Format "2006-01-02T15:04:05-0700") | safeHTMLAttr }}>
{{ with .Params.author | default site.Params.author.name }}<meta name="author" content="{{ . }}">{{ end }} {{ with .Params.author | default site.Params.author.name }}<meta name="author" content="{{ . }}">{{ end }}