add json-ld structured data partial

This commit is contained in:
Robert Kaussow 2020-07-24 22:25:04 +02:00
parent 247a1f7263
commit 07f124360d
Signed by: xoxys
GPG Key ID: 65362AE74AF98B61
9 changed files with 92 additions and 17 deletions

View File

@ -1,2 +1,6 @@
- BREAKING
- rename description and keyword variables
- rename logo variable
- rename subtitle variable
- ENHANCEMENT
- move description and keyword variables
- add partial for json-ld structured data

View File

@ -54,13 +54,13 @@ outputs:
enableRobotsTXT: true
params:
images:
- "favicon/android-chrome-512x512.png"
subtitle: Subtitle to describe your blog
description: >
hugo-geekblog is a simple Hugo theme for personal blogs. This page is theme documentation
and powered by the latest version of hugo-geekblog itself.
images:
- "favicon/android-chrome-512x512.png"
geekblogSubtitle: Subtitle to describe your blog
geekblogToC: 3
geekblogAuthor: john-doe

View File

@ -88,19 +88,20 @@ enableGitInfo = true
term = ["HTML", "ATOM"]
[params]
subtitle =
description = "This is my personal blog about tech."
keywords = []
images = []
# (Optional, default static/brand.svg) Set the path to a logo for the Geekblog
# relative to your 'static/' folder.
logo = logo.png
# (Optional, default 6) Set how many table of contents levels to be showed on page.
# Use false to hide ToC, note that 0 will default to 6 (https://gohugo.io/functions/default/)
# You can also specify this parameter per page in front matter.
geekblogToC = 3
# (Optional, default static/brand.svg) Set the path to a logo for the Geekblog
# relative to your 'static/' folder.
geekblogLogo = logo.png
# (Optional, default none) Add a link to your Legal Notice page to the site footer.
# It can be either a remote url or a local file path relative to your content directory.
geekblogLegalNotice = "https://blog.example.com/legal"
@ -198,19 +199,20 @@ outputs:
enableRobotsTXT: true
params:
subtitle:
description: "This is my personal blog about tech."
keywords: []
images: []
# (Optional, default static/brand.svg) Set the path to a logo for the Geekblog
# relative to your 'static/' folder.
logo: logo.png
# (Optional, default 6) Set how many table of contents levels to be showed on page.
# Use false to hide ToC, note that 0 will default to 6 (https://gohugo.io/functions/default/)
# You can also specify this parameter per page in front matter.
geekblogToC: 3
# (Optional, default static/brand.svg) Set the path to a logo for the Geekblog
# relative to your 'static/' folder.
geekblogLogo: logo.png
# (Optional, default none) Add a link to your Legal Notice page to the site footer.
# It can be either a remote url or a local file path relative to your content directory.
geekblogLegalNotice: https://blog.example.com/legal

View File

@ -9,6 +9,7 @@
{{ partial "head/rel-me" . }}
{{ partial "head/microformats" . }}
{{ partial "head/others" . }}
{{ partial "head/schema.html" . }}
</head>
<body>

View File

@ -8,7 +8,7 @@
{{- end -}}
{{- end -}}
{{ printf `<title type="html"><![CDATA[%s]]></title>` $title | safeHTML }}
{{ with .Site.Params.GeekblogSubtitle }}
{{ with .Site.Params.subtitle }}
{{ printf `<subtitle type="html"><![CDATA[%s]]></subtitle>` . | safeHTML }}
{{ end }}
{{ $output_formats := .OutputFormats }}

View File

@ -1,6 +1,6 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{{ $description := default (default .Site.Title .Site.Params.Description) (default .Summary .Description) }}
{{ $description := default (default .Site.Title .Site.Params.description) (default .Summary .Description) }}
{{ $keywords := default .Site.Params.Keywords .Keywords }}
{{ $author := default (slice .Site.Params.GeekblogAuthor) .Params.authors }}
{{ with $description }}

View File

@ -1,3 +1,2 @@
{{ template "_internal/opengraph.html" . }}
{{ template "_internal/twitter_cards.html" . }}
{{ template "_internal/schema.html" . }}

View File

@ -0,0 +1,69 @@
{{ if .IsHome -}}
<script type="application/ld+json">
{
"@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 }}",
"description": "{{ .Site.Params.description }}",
"thumbnailUrl": "{{ (default "brand.svg" .Site.Params.logo) | absURL }}"{{ with .Site.Params.GeekblogContentLicense }},
"license": "{{ .name }}"{{ end }}
}
</script>
{{ else if .IsPage }}
{{ $authors := default (slice .Site.Params.GeekblogAuthor) .Params.authors }}
{{ $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 }}",
"description": "{{ if .Description }}{{ .Description | safeJS }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ end }}{{ end }}",
"inLanguage": {{ .Site.Language.Lang }},
"isFamilyFriendly": "true",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "{{ .Permalink }}"
},
"author" : [
{{- with $authors -}}
{{- range sort . }}
{{- $ac = (add $ac 1) }}
{{- $author := index $.Site.Data.authors . }}
{
"@type": "Person",
"name": "{{ $author.name }}"
}{{ if lt $ac $ac_max }},{{ end }}
{{- end -}}
{{- end }}
],
"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"
}
},
"image": {{ if .Params.images }}[{{ range $i, $e := .Params.images }}{{ if $i }}, {{ end }}{{ $e | absURL }}{{ end }}]{{ else}}{{.Site.Params.logo | absURL }}{{ end }},
"url" : "{{ .Permalink }}",
"wordCount" : "{{ .WordCount }}",
"genre" : [ {{ range $index, $tag := .Params.tags }}{{ if $index }}, {{ end }}"{{ $tag }}" {{ end }}]
}
</script>
{{ end }}

View File

@ -2,10 +2,10 @@
<div class="container flex align-center justify-center">
<a class="gblog-header__link" rel="me" href="{{ .Site.BaseURL }}">
<span class="gblog-brand flex align-center justify-center">
<img class="gblog-brand__img" title="Branding of {{ .Site.Title }}" src="{{ (default "brand.svg" .Site.Params.GeekblogLogo) | relURL }}" alt="{{ .Site.Title }}" width=60 height=60>
<img class="gblog-brand__img" title="Branding of {{ .Site.Title }}" src="{{ (default "brand.svg" .Site.Params.logo) | relURL }}" alt="{{ .Site.Title }}" width=60 height=60>
{{ .Site.Title }}
</span>
{{ with .Site.Params.GeekblogSubtitle }}
{{ with .Site.Params.subtitle }}
<span class="gblog-brand__subtitle flex align-center justify-center">{{ . }}</span>
{{ end }}
</a>