Zotero-Nikola Harmony (One Simple Trick)

TL;DR: Modify the post-related templates in your active theme to add the following to the <head> element in each post:

<meta property="zotero:itemType" content="blogPost">

Also, make sure to define the zotero namespace prefix for this property in the prefix attribute on the <html> element. The proper value is http://www.zotero.org/namespaces/export#.

Explanation and Example

The surest way I've found to make the Firefox plugin for Zotero Standalone recognize my blog posts as blog posts (rather than just as generic web pages) is to insert a <meta> element in the HTML <head> for each post. The <meta> element must make use of a property attribute containing the name of the Zotero field we want to specify (in this case, itemType). You won't find @property in the HTML5 specification; it's defined by RDFa. You also need a content attribute on the <meta> element to carry the value Zotero expects, i.e., blogPost. Thus:

<!DOCTYPE html>
<html prefix="og: http://ogp.me/ns# 
  article: http://ogp.me/ns/article# 
  zotero: http://www.zotero.org/namespaces/export# " 
  lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Zotero Item Keys (Again) | paregorios.org</title>
    <link href="../../../../assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="../../../../assets/css/baguetteBox.min.css" rel="stylesheet" type="text/css">
    <link href="../../../../assets/css/rst.css" rel="stylesheet" type="text/css">
    <link href="../../../../assets/css/code.css" rel="stylesheet" type="text/css">
    <link href="../../../../assets/css/theme.css" rel="stylesheet" type="text/css">
    <link href="../../../../assets/css/custom.css" rel="stylesheet" type="text/css">
    <meta name="theme-color" content="#5670d4">
    <meta name="generator" content="Nikola (getnikola.com)">
    <link rel="alternate" type="application/rss+xml" title="RSS" href="../../../../rss.xml">
    <link rel="canonical" href="https://paregorios.org/posts/2018/05/zotero_item_keys/">
    <!--[if lt IE 9]><script src="../../../../assets/js/html5.js"></script><![endif]-->
    <meta name="author" content="Tom Elliott">
    <link rel="prev" href="../../04/bervus/" title="A Roman Tombstone from Heidelberg" type="text/html">
    <meta property="og:site_name" content="paregorios.org">
    <meta property="og:title" content="Zotero Item Keys (Again)">
    <meta property="og:url" content="https://paregorios.org/posts/2018/05/zotero_item_keys/">
    <meta property="og:description" content="Back in 2012, I posted about Zotero item keys and my attempts ...">
    <meta property="og:type" content="article">
    <meta property="article:published_time" content="2018-05-01T05:13:26-05:00">
    <meta property="article:tag" content="bibliography">
    <meta property="article:tag" content="zotero">
    <meta property="zotero:itemType" content="blogPost">
  </head>

How to implement in Nikola

The Nikola static site generator, which I use for paregorios.org, uses a templating system to generate the HTML pages that are then deployed to the server (I author in Markdown; Nikola supports a variety of authoring formats). So, I needed to modify the template(s) used for the individual HTML files that go in the "posts" section of the site so that they include the magic Zotero metadata described above. The Nikola Handbook, as currently written, makes it sound like you have to create your own custom theme (a collection of templates and CSS files) if you want to modify template behavior, but that it is not the case. You can selectively override templates from whatever stock or third-party theme you have installed and configured.

I use the "bootstrap4" theme that ships with Nikola 8, rather than the default "bootblog4" (one changes this via the THEME variable in conf.py), so I went poking around in the code to find out how and where the <html>, <head>, and <meta> elements get generated. I discovered that -- in the boostrap4 theme -- there are three templates involved: post.tmpl, post_helper.tmpl, and base_helper.tmpl. Nikola makes it easy to get copies of those templates for the purpose of overriding. I entered the following commands and the command line:

nikola theme -c post.tmpl
nikola theme -c post_helper.tmpl
nikola theme -c base.tmpl

Nikola created a templates subdirectory for me and copied the three files into it. Any changes I make in those copies are reflected in output the next time I run nikola build.

To get the behavior I wanted I had to do the following:

  1. Modify templates/base_helper.tmpl to define the zotero namespace prefix,
  2. Modify templates/post_helper.tmpl to write the Zotero-related <meta> element I want, and
  3. Modify templates/post.tmpl to invoke the code I added to templates/post_helper.tmpl.

Select this link for a diff via github that shows you what I changed.

A Note on the Zotero Namespace

Exceptionally devoted readers may recall that my last post on this subject prophesied the use of the PRISM namespace to achieve Nikola+Zotero harmony. In fact, I tried adding <meta property="prism:genre" content="blogentry"> based on what I was seeing in the Zotero translator code, but got no joy (i.e., Zotero was still identifying my blog posts as generic web pages). I had two options: either try to troubleshoot the relatively complex logic used in the Zotero translator to find out what I was doing wrong or why some other value was getting prioritized over my PRISM metadata, or take a cue from the big assignment in the Zotero translator code that prioritizes a Zotero item type over any other metadata scheme. Embracing laziness as a virtue -- and also noticing that in newer versions of PRISM "blogEntry" seems to have been moved from the Genre vocabulary where the Zotero translator expects it to the Content Type vocabulary -- I went with the latter option, got the result I was looking for, committed the changes, redeployed, wrote this blog post, and moved on to other things.