hugo-geekblog/layouts/partials/head/schema.html

87 lines
3.0 KiB
HTML
Raw Normal View History

2020-07-24 20:25:04 +00:00
{{ if .IsHome -}}
{{ $thumbnail := default (default "brand.svg" .Site.Params.logo) (index (default slice .Site.Params.images) 0) | absURL }}<script type="application/ld+json">
2020-07-24 20:25:04 +00:00
{
"@context": "http://schema.org",
"@type": "WebSite",
{{ with .Site.Params.GeekblogAuthor -}}
{{ with index $.Site.Data.authors . }}"author": "{{ .name }}",{{ end }}
{{- end }}
"name": "{{ .Site.Title }}",
"url": "{{ .Site.BaseURL }}",
2020-07-25 11:53:27 +00:00
{{- with .Site.Params.description }}
"description": "{{ . }}",
{{- end }}
2020-07-26 12:47:51 +00:00
"thumbnailUrl": "{{ $thumbnail }}"
2020-07-25 11:53:27 +00:00
{{- with .Site.Params.GeekblogContentLicense }},
"license": "{{ .name }}"
{{- end }}
2020-07-24 20:25:04 +00:00
}
</script>
{{ else if .IsPage }}
{{ $authors := default (slice .Site.Params.GeekblogAuthor) .Params.authors }}
2020-07-25 11:53:27 +00:00
{{ $description := default .Site.Params.description (default .Description .Summary) }}
2020-07-24 20:25:04 +00:00
{{ $ac := 0 }}
{{ $ac_max := default 0 (len $authors) }}
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BlogPosting",
"articleSection": "{{ .Section }}",
"name": "{{ .Title | safeJS }}",
"headline": "{{ .Title | safeJS }}",
"alternativeHeadline": "{{ .Params.lead }}",
2020-07-25 11:53:27 +00:00
{{- with $description }}
"description": "{{ . }}",
{{- end }}
2020-07-24 20:25:04 +00:00
"inLanguage": {{ .Site.Language.Lang }},
"isFamilyFriendly": "true",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "{{ .Permalink }}"
},
2020-07-25 11:53:27 +00:00
{{- with $authors }}
2020-07-24 20:25:04 +00:00
"author" : [
{{- range sort . }}
{{- with . -}}
2020-07-24 20:25:04 +00:00
{{- $ac = (add $ac 1) }}
{{- $author := index $.Site.Data.authors . }}
{
"@type": "Person",
"name": "{{ $author.name }}"
}{{ if lt $ac $ac_max }},{{ end }}
{{- end -}}
2020-07-25 11:53:27 +00:00
{{- end }}
2020-07-24 20:25:04 +00:00
],
2020-07-25 11:53:27 +00:00
{{- end }}
2020-07-24 20:25:04 +00:00
"copyrightHolder" : "{{ .Site.Title }}",
"copyrightYear" : "{{ .Date.Format "2006" }}",
"dateCreated": "{{ .Date.Format "2006-01-02T15:04:05.00Z" | safeJS }}",
"datePublished": "{{ .PublishDate.Format "2006-01-02T15:04:05.00Z" | safeJS }}",
"dateModified": "{{ .Lastmod.Format "2006-01-02T15:04:05.00Z" | safeJS }}",
"publisher":{
"@type":"Organization",
"name": {{ .Site.Title }},
"url": {{ .Site.BaseURL }},
"logo": {
"@type": "ImageObject",
"url": "{{ (default "brand.svg" .Site.Params.logo) | absURL }}",
"width":"32",
"height":"32"
}
},
2020-07-26 12:47:51 +00:00
{{- with $images := $.Resources.ByType "image" }}
"image": [ {{ range $i, $image := $images }}{{ if $i }}, {{ end }}"{{ $image.Permalink | absURL }}" {{ end }}],
{{- else }}
{{- with $images := .Params.images }}
"image": [ {{ range $i, $image := $images }}{{ if $i }}, {{ end }}"{{ $image | absURL }}" {{ end }}],
{{- end }}
{{- end }}
2020-07-24 20:25:04 +00:00
"url" : "{{ .Permalink }}",
"wordCount" : "{{ .WordCount }}",
{{- with $tags := .Params.tags }}
"genre" : [ {{ range $i, $tag := $tags }}{{ if $i }}, {{ end }}"{{ $tag }}" {{ end }}]
{{- end }}
2020-07-24 20:25:04 +00:00
}
</script>
{{ end }}