Add basic schema.org data

This commit is contained in:
BBaoVanC 2021-11-19 19:16:06 -06:00
parent 7a73432238
commit 1f080d9092
Signed by: bbaovanc
GPG Key ID: 18089E4E3CCF1D3A
2 changed files with 52 additions and 0 deletions

View File

@ -33,6 +33,7 @@
{{ partial "opengraph.html" . }}
{{ partial "twitter_cards.html" . }}
{{ partial "schema.html" . }}
{{ partial "seo_schema.html" . }}
<meta name="description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}">

View File

@ -0,0 +1,51 @@
{{/* See https://github.com/spech66/hugo-best-practices#add-a-schemaorg-partial */}}
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "{{ .Site.BaseURL }}"
},
"articleSection" : "{{ .Section }}",
"name" : "{{ .Title }}",
"headline" : "{{ .Title }}",
// "description" : "{{ if .Description }}{{ .Description }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ end }}{{ end }}",
"description" : "{{ with .Description }}{{ . }}{{ else }}{{ .Site.Params.description }}{{ end }}",
"inLanguage" : "{{ .Lang }}",
{{ with .Params.authors -}}
"author" : [
{{ $len := len . }}
{{ range $i, $author := . -}}
{{ $url := (printf `authors/%s` ($author | anchorize)) -}}
{
"@type": "Person",
"name": "{{ $author }}",
"url": "{{ $url | absLangURL }}",
{{ with ($.Site.GetPage $url) -}}
"description": "{{ with .Description }}{{ . | plainify }}{{ end }}"
{{ end -}}
{{ if eq (add $i 1) $len -}}
}
{{ else }}
},
{{ end }}
{{ end -}}
],{{ end }}
{{ $images := $.Resources.ByType "image" -}}
{{ $featured := $images.GetMatch "*feature*" -}}
{{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
{{ with $featured -}}
"image": "{{ .Permalink }}",
{{ end }}
"copyrightYear" : "{{ .Date.Format "2006" }}",
"datePublished": "{{ .Date | safeHTML }}",
"dateModified" : "{{ .Lastmod | safeHTML }}",
"url" : "{{ .Permalink }}",
"wordCount" : "{{ .WordCount }}",
"keywords" : [ {{ if isset .Params "tags" }}{{ range .Params.tags }}"{{ . }}",{{ end }}{{ end }} "Blog" ]
}
</script>