summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--exampleSite/config.toml5
-rw-r--r--layouts/_default/list.json.json4
-rw-r--r--layouts/partials/head.html1
-rw-r--r--layouts/partials/schema.org/article.html65
-rw-r--r--layouts/partials/schema.org/website.html10
-rw-r--r--layouts/partials/templates/schema_json.html5
7 files changed, 90 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f6ffd40..debdd05 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add tagging support
- Provide ability to hide particular page from the sitemap by using
`private: true` in front matter
+- Provided initial support os schema.org microdata for the site
+ and for the posts
### Changed
diff --git a/exampleSite/config.toml b/exampleSite/config.toml
index 1141174..5ef6fe6 100644
--- a/exampleSite/config.toml
+++ b/exampleSite/config.toml
@@ -176,6 +176,11 @@ disableKinds = ['RSS']
logo = '/img/open-graph-logo.png' # Logo image, relative to ./assets
disable_fingerprinting = false
+ [params.seo]
+ # Will be used in schema.org/Organization.
+ # The site.Title will be used if empty.
+ publisher = 'Serghei Iakovlev'
+
[social]
# Facebook Page Admin ID for Domain Insights
facebook_admin = ''
diff --git a/layouts/_default/list.json.json b/layouts/_default/list.json.json
index 70ea7a4..f6b89cc 100644
--- a/layouts/_default/list.json.json
+++ b/layouts/_default/list.json.json
@@ -16,7 +16,7 @@
{
"version": "https://jsonfeed.org/version/1.1",
- "title": {{ (printf "%s" (partial "title.html" .)) | htmlUnescape | jsonify }},
+ "title": {{ (partial "title.html" .) | htmlUnescape | jsonify }},
"home_page_url": {{ printf "%s?utm_source=json_feed" site.BaseURL | absURL | jsonify }},
{{ with .OutputFormats.Get "JSON" }}"feed_url": {{ .Permalink | absURL | jsonify }},{{ end }}
{{ with site.Params.description}}"description": {{ site.Params.description | jsonify }},{{ end }}
@@ -39,6 +39,6 @@
"date_published": {{ .PublishDate.Format "2006-01-02T15:04:05Z07:00" | jsonify }}{{ if ne .Date .Lastmod }},
"date_modified" : {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" | jsonify }}{{ end }}
}
- {{- end}}
+ {{- end }}
]
}
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 39e3255..00a5f82 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -33,4 +33,5 @@
{{- /* Misc */}}
{{ template "partials/templates/opengraph.html" . }}
{{ template "partials/templates/twitter_cards.html" . }}
+ {{ template "partials/templates/schema_json.html" . }}
</head>
diff --git a/layouts/partials/schema.org/article.html b/layouts/partials/schema.org/article.html
new file mode 100644
index 0000000..ff1558b
--- /dev/null
+++ b/layouts/partials/schema.org/article.html
@@ -0,0 +1,65 @@
+{{- /* Get schema type. */}}
+{{ $schemaType := "Article" }}
+{{ if or (eq .Type "post") (eq .Type "posts") }}
+ {{ $schemaType = "BlogPosting" }}
+{{ end -}}
+
+{{- $publisher := site.Params.seo.publisher | default site.Title }}
+{{ $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png") }}
+{{ $logo = $logo.Resize "96x96" -}}
+
+<script type="application/ld+json">
+ {
+ "@context": "https://schema.org",
+ "@type": {{ $schemaType }},
+ "mainEntityOfPage": {
+ "@type": "WebPage",
+ "@id": {{ .Permalink }}
+ },
+ "headline": {{ partial "title.html" . | htmlUnescape }},{{ if .Params.featured_image }}
+ {{ $image := .Resources.GetMatch .Params.featured_image -}}
+ "image": [
+ {{ $image.Permalink }}
+ ],{{ end }}
+ "datePublished": {{ .Date.Format "2006-01-02T15:04:05Z07:00" }},
+ "dateModified": {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }},
+ {{- if .Params.author }}
+ {{- $authorType := (printf "%T" .Params.author) }}
+ {{- if eq $authorType "string" }}
+ "author": {
+ "@type": "Person",
+ "name": {{ .Params.author }}
+ },
+ {{- else if eq $authorType "[]string" }}
+ "author": [
+ {{ range $i, $author := .Params.author }}{{ if $i }},{{ end }}
+ {
+ "@type": "Person",
+ "name": {{ $author }}
+ }{{ end }}
+ ],
+ {{- end }}
+ {{- else }}
+ {{- with site.Author.name }}
+ "author": {
+ "@type": "Person",
+ "name": {{ . }}
+ {{ with site.Author.twitter }},
+ "url": "https://twitter.com/{{ . }}"
+ {{ end }}
+ },
+ {{- end }}
+ {{- end }}
+ "publisher": {
+ "@type": "Organization",
+ "name": {{ $publisher }},
+ "logo": {
+ "@type": "ImageObject",
+ "url": {{ $logo.Permalink | absURL }}
+ }
+ },
+ "description": {{ partial "description.html" . }}
+ }
+</script>
+
+
diff --git a/layouts/partials/schema.org/website.html b/layouts/partials/schema.org/website.html
new file mode 100644
index 0000000..ef6609e
--- /dev/null
+++ b/layouts/partials/schema.org/website.html
@@ -0,0 +1,10 @@
+<script type="application/ld+json">
+ {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ "name": {{ partial "title.html" . }},
+ "url": {{ site.BaseURL }}
+ }
+</script>
+{{- /* TODO: Add "potentialAction" with search.
+ For more see: https://developers.google.com/structured-data/slsb-overview */ -}}
diff --git a/layouts/partials/templates/schema_json.html b/layouts/partials/templates/schema_json.html
new file mode 100644
index 0000000..aaed1e2
--- /dev/null
+++ b/layouts/partials/templates/schema_json.html
@@ -0,0 +1,5 @@
+{{ if .IsHome }}
+ {{ partial "schema.org/website.html" . }}
+{{ else if and .IsPage (ne .Params.private true) }}
+ {{ partial "schema.org/article.html" . }}
+{{ end }}