Per Article Meta Informations with The Pelican Static Site Generator

Wed 06 November 2013

I am really happy with Pelican, the static site generator that I use to create the pages of this blog.

Nevertheless, I had a small nitpick: I did not know how to provide a per article Facebook open graph tag for the image, which means that all posts had my stupid face accompanying the title of an article when somebody shared it on Facebook (or on Google+, as they also read these tags). More generally, I am interested by the idea of being able to provide specific meta information per post instead.

It turns out that it is quite easy to do: if you use Markdown as the input language as I do (It's a pleasure with Mou), you can simply add more meta information after your existing metas at the top of your file. For example, for this very post, I added the FacebookImage meta at the end of the header of my markdown file, like this:

Title: Per Article Meta Informations with The Pelican Site Generator
Date: 2013-11-06 10:06
Slug: metas-with-pelican-site-generator
Author: Martin De Wulf
Summary: A quick tip about the software that powers this blog
FacebookImage: http://multitasked.net/images/pelican.png

Now, to use this meta in your templates, it is very easy. It is available as a field of the article object that is available in the context of your template.

For example for the FacebookImage meta, you can use it like this in your template:

 <meta property="og:image" content="{{article.facebookimage}}"/>

The only catch being that the name of the field of the article object has been downcased by Pelican. You can check in the source code of this page that it worked.

Nothing very complex, but this took me some time to figure out, so, I thought that I might as well write it down.

Now, I just have to type make ssh_upload and all this will be online. I really like Pelican!

Feed - About me

comments powered by Disqus