JSON-LD is a useful way to add semantic mark up your output with schema.org objects. From their site:
JSON-LD is a lightweight Linked Data format. It is easy for humans to read and write. It is based on the already successful JSON format and provides a way to help JSON data interoperate at Web-scale. JSON-LD is an ideal data format for programming environments, REST Web services, and unstructured databases such as CouchDB and MongoDB.
I like this better than marking up with interspersed itemscope, itemtype or itemprop, since it’s all in one block and just easy to read.
Here’s how I’m doing it. I hope it helps someone.
Given a config.toml with:
+++
...
ISO8601 = "2006-01-02T15:04:05JST"
...
+++
… specifying my timezone JST (Japan time, noting that server is also set to this), and a partial template called in my <head>
that is meant to render json-ld
markup for a schema.org BlogPosting
schema:
{{ "<!-- ENTERING partial seo-schema.html -->" | safeHTML }}
{{ if .IsPage }}
{{ if eq .Type "post" }}
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "BlogPosting",
"articleSection" : "{{ .Section }}",
"name" : "{{ .Title }}",
"headline" : "{{ .Title }}",
"description" : "{{ if .Description }}{{ .Description }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ end }}{{ end }}",
"inLanguage" : "en-US",
"author" : "{{ .Params.author }}",
"creator" : "{{ .Params.author }}",
"accountablePerson" : "{{ .Params.author }}",
"copyrightHolder" : "{{ .Params.author }}",
"copyrightYear" : "{{ .Date.Format "2006" }}",
"datePublished": "{{ .PublishDate.Format $.Site.Params.ISO8601 }}",
"dateModified" : "{{ .Date.Format $.Site.Params.ISO8601 }}",
"url" : "{{ .Permalink }}",
"wordCount" : "{{ .WordCount }}",
"image" : [ {{ range $i, $e := .Params.images }}{{ if $i }}, {{ end }}{{ $e }}{{ end }} ],
"keywords" : [ {{ range $i, $e := .Params.tags }}{{ if $i }}, {{ end }}{{ $e }}{{ end }} ]
}
</script>
{{ end }}
{{ end }}
{{ "<!-- LEAVING partial seo-schema.html -->" | safeHTML }}
… then, with a post markdown file yaml frontmatter like this, with the default hugo new
date format including a +09:00
to indicate timezone:
---
author: Rick Cogley
authorlink: /about
authortwitter: https://twitter.com/rickcogley
banner: https://farm5.staticflickr.com/4059/5135448447_95b026227b_o.jpg
date: 2015-05-08T12:33:19+09:00
publishdate: 2015-05-08T12:33:19+09:00
description: The rsync that Apple provides in OS X Yosemite is out of date, but you can easily upgrade it using the homebrew package manager - a post by Rick Cogley.
draft: "false"
showauthor: "true"
showcomment: "true"
showdate: "true"
showpaging: "true"
showreadingtime: "true"
showsocialsharing: "true"
showtoc: "true"
showtotop: "true"
slug: upgrade-outdated-rsync-on-osx
subtitle: Homebrew to the rescue
tags:
- brew
- tap
- rsync
- homebrew
- upgrade
- osx
- mac
title: Old rsync on OS X?
topics:
- Tips
- SysAdmin
- Upgrades
news_keywords:
- brew
- tap
- rsync
- homebrew
- upgrade
- mac
- osx
images:
- /img/homebrew.png
- http://static.cogley.info/img/rick-cogley-avatar-900x900.jpg
---
… I get this as the result, in view source:
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "BlogPosting",
"articleSection" : "post",
"name" : "Old rsync on OS X?",
"headline" : "Old rsync on OS X?",
"description" : "The rsync that Apple provides in OS X Yosemite is out of date, but you can easily upgrade it using the homebrew package manager - a post by Rick Cogley.",
"inLanguage" : "en-US",
"author" : "Rick Cogley",
"creator" : "Rick Cogley",
"accountablePerson" : "Rick Cogley",
"copyrightHolder" : "Rick Cogley",
"copyrightYear" : "2015",
"datePublished": "2015-05-08T12:33:19JST",
"dateModified" : "2015-05-08T12:33:19JST",
"url" : "http:\/\/localhost:1313\/post\/upgrade-outdated-rsync-on-osx",
"wordCount" : "214",
"image" : [ "/img/homebrew.png", "http://static.cogley.info/img/rick-cogley-avatar-900x900.jpg" ],
"keywords" : [ "brew", "tap", "rsync", "homebrew", "upgrade", "osx", "mac" ]
}
</script>
Amongst other semantic formats, at least the above source validates in Schema Markup Testing Tool | Google Search Central | Google for Developers.