How to publish org-mode to HTML5+RDFa

Table of Contents

The goal is to ensure I can author HTML5+RDFa easily in org-mode.

Principle

I'd like to add meta-data in the generated HTML exports of a publishing project, while keeping the syntax as compact as possible.

I'm doing this by identifying a few RDFa constructs that will be used frequently, for which I'll add a predefined custom link type.

The following :

[[rlink:link_to_resource :typeof "foaf:Person" :about "http://www-public.telecom-sudparis.eu/~berger_o/foaf.rdf#me" :rel "foaf:homepage" :href "https://www-public.tem-tsp.eu/~berger_o/"][My homepage]]

will then be exported to HTML as :

<span about="http://www-public.telecom-sudparis.eu/~berger_o/foaf.rdf#me" tyepof="foaf:Person" rel="foaf:homepage"><a href="https://www-public.tem-tsp.eu/~berger_o/">My homepage</a></span>

When Descriptive links is activated, the link will just look like a classical [[https://www-public.tem-tsp.eu/~berger_o/][My homepage]] (i.e. a blue link behind My homepage),which won't clutter the buffer.

I have followed the guidelines set by John Kitchin in Extending the org-mode link syntax with attributes for doing so.

The special rlink link will allow exporting different RDFa constructs :

  • link_to_resource links like the above,
  • article resource descriptions for research articles (yeah, my homepage links to my papers ;)

The results can be seen on my My homepage (note that this very link uses the [[rlink: construct : inspect the HTML source of this page :-)..

Adding a custom link type

In this file, we add an emacs-lisp babel code block, that will create a custom link type, named rlink which will allow adding RDFa in our document.

My elisp style can probably be improved (suggestions welcome ;).

To embedd this in the index.org of the publishing project, I'm using :

#+NAME: add-rlink-link-type
#+BEGIN_SRC emacs-lisp :results silent :exports results
  (org-add-link-type
   "rlink"
...
#+END _SRC <--- NOTE: this should be #+END_SRC, so fix it if you copy/paste

At the bottom, I'm adding

# Local Variables:
# org-confirm-babel-evaluate: (lambda (lang body) (not (string= lang "emacs-lisp")))
# End:

This ensures that I'm allowing the add-rlink-link-type invocation at every publishing/export once, when loading index.org.

Generating HTML5+RDFa

The documents need to be adapted so that HTML5 is generated, and so that embedded RDFa is valid.

This requires a few bits (please report missing ones), mainly in the org templates.

Adpating the org templates

The HTML_DOCTYPE needs to be set to xhtml5 and the HTML needs to be valid in the templates. Something like :

#+LANG: fr
#+OPTIONS: html-link-use-abs-url:nil html-postamble:auto
#+OPTIONS: html-preamble:t html-scripts:t html-style:nil
#+OPTIONS: html5-fancy:nil tex:t
#+OPTIONS: num:nil
#+HTML_CONTAINER: div
#+HTML_DOCTYPE: xhtml5

Adding prefixes

The content will be enclosed inside a <div> which will add the necessary RDF prefixes

#+HTML:<div prefix="foaf: http://xmlns.com/foaf/0.1/ org: http://www.w3.org/ns/org# biblio: http://purl.org/net/biblio#">

... content ...

#+HTML:</div>

Citing articles

The following :

Olivier Berger and Christian Bac: [[rlink:article :about "#debianptsadmssw2013" :creator "http://www-public.telecom-sudparis.eu/~berger_o/foaf.rdf#me" :sameas "http://www-public.telecom-sudparis.eu/~berger_o/papier-oss2013/"][Authoritative linked data descriptions of debian source packages using ADMS.SW]].
In Etiel Petrinja, Giancarlo Succi, Nabil Ioini, and Alberto Sillitti, editors, Open Source Software : Quality Verification, volume 404 of IFIP Advances in Information and Communication Technology, pages 168–181. Springer Berlin Heidelberg, 2013.

will then be exported to HTML as :

Olivier Berger and Christian Bac: <span about="#debianptsadmssw2013" typeof="biblio:Reference"><span rel="dcterms:creator" resource="http://www-public.telecom-sudparis.eu/~berger_o/foaf.rdf#me"></span><span rel="owl:sameAs" resource="http://www-public.telecom-sudparis.eu/~berger_o/papier-oss2013/"></span><i><span property="dcterms:title">Authoritative linked data descriptions of debian source packages using ADMS.SW</span></i></span>.
In Etiel Petrinja, Giancarlo Succi, Nabil Ioini, and Alberto Sillitti, editors, Open Source Software : Quality Verification, volume 404 of IFIP Advances in Information and Communication Technology, pages 168–181. Springer Berlin Heidelberg, 2013.

Adding custom RDF

This may be done by using, for instance

#+BEGIN_HTML
  <span about="http://www-public.telecom-sudparis.eu/~berger_o/foaf.rdf#me" rel="org:memberOf" resource="#tsp"></span>
  <span about="#imt" rel="org:hasSite" resource="#tsp"></span>
  <span about="#imt" rel="owl:sameAs" resource="http://dbpedia.org/resource/Institut_Telecom"></span>
  <span about="#tsp" rel="owl:sameAs" resource="http://dbpedia.org/resource/Telecom_SudParis"></span>
#+END_HTML

Created: 2015-04-21 mar. 11:49

Made with Org-mode in Emacs

Validate