Skip to content

Commit

Permalink
add json-ld structured data partial
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxys committed Jul 24, 2020
1 parent 247a1f7 commit 07f1243
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 17 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions exampleSite/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 10 additions & 8 deletions exampleSite/content/posts/how-to-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{{ partial "head/rel-me" . }}
{{ partial "head/microformats" . }}
{{ partial "head/others" . }}
{{ partial "head/schema.html" . }}
</head>

<body>
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/list.atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/head/meta.html
Original file line number Diff line number Diff line change
@@ -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 }}
Expand Down
1 change: 0 additions & 1 deletion layouts/partials/head/microformats.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
{{ template "_internal/opengraph.html" . }}
{{ template "_internal/twitter_cards.html" . }}
{{ template "_internal/schema.html" . }}
69 changes: 69 additions & 0 deletions layouts/partials/head/schema.html
Original file line number Diff line number Diff line change
@@ -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 }}
4 changes: 2 additions & 2 deletions layouts/partials/site-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 07f1243

Please sign in to comment.