Embedly Cards Pelican plugin

Technology ?? Comments Sun 23 March 2014
UPDATE: Embedly Cards v0.2 now supports Markdown

This blog is built using Pelican [1], an awesome static blog generator written in Python, requiring no database or server-side scripting - in fact, all content is generated from simple reStructuredText or Markdown files (including this page, if you look at the source). Compared to a CMS like Wordpress, this results in increased speed, the ability to use static "web-hosts" (like GitHub or Dropbox - not strictly what they were designed for, especially Dropbox, but it works - and they're free!), and, depending on your point of view, easier content management/backup. Of course, you lose certain features, like online or mobile posting, but with DroidEdit on Android now supporting Git, online editing of files on GitHub, and the ability to build your site automatically on git pushes using continuous integration sites such as Travis CI (see this tutorial), it's very nearly there.

However, as reStructuredText is not designed for dynamic web content, embedding external content is difficult - this is alleviated somewhat by Pelican plugins such as Pelican-Youtube and Pelican-Vimeo, but this approach requires the continual development of similar plugins for further types of content. On the other end of the spectrum, there is html_rst_directive; but this requires that

  1. the external site provides easy-to-access HTML for embeddable content
  2. and if it does, you will probably need to be on the desktop site, excluding phone apps/sites/blogging-on-the-go.

Another approach is a Python plugin using the oEmbed standard, allowing the embeddable HTML to be recieved and inserted on blog generation. I played around with two such plugins, PyEmbed and sphinxcontrib.embedly, the latter of which uses Embed.ly oEmbed central repository. Whilst both are nice solutions, I still wasn't able to embed all the sources I was hoping to.

However, I noticed that Embed.ly has a new poduct called Embed.ly Cards:

Cards provide a clean, responsive, and shareable card for any content on the web. Use them to make your posts easier to share and repost across the web. You can also include rich content from other sites in your own posts with Cards.

The produced embeddable cards support almost any source - articles, Amazon products, YouTube videos, PDFs, forum posts, etc (even Google+ albums!). What's more, they look really good, with a subtle coloured left border giving a 'quote' effect, rich content, and a short excerpt if available - this is the sort of standardised formatting I was looking for. They can even be used for your own content, providing a 'richer' linking experience between blog posts!

Embedly-cards plugin

So I wrote a small Pelican plugin allowing Embed.ly cards to be easily inserted in posts; the source code is available on Github, and it can be installed using pip:

$ pip install embedly-cards

Check out the Github repo for more information. Below are some quick examples.


Embedding a Google+ album:

.. embedly-card:: https://plus.google.com/photos/107452285898786120113/albums/5962126455360751089?authkey=CKv687-PodGg0gE

Embedding a photo:

.. embedly-card:: https://lh5.googleusercontent.com/n7iY8f5n8qJcZraH3bvRJdpdZiYlsT_wU5ZZznpKIxHU=w1351-h901-no

Embedding an StackOverflow post:

.. embedly-card:: http://physics.stackexchange.com/questions/5265/cooling-a-cup-of-coffee-with-help-of-a-spoon

Embedding a YouTube video with card border:

.. embedly-card:: https://www.youtube.com/watch?v=E43-CfukEgs
        :card-chrome: 1

Embedding a YouTube video without card border:

.. embedly-card:: https://www.youtube.com/watch?v=E43-CfukEgs

An embedded PDF:

.. embedly-card:: https://dl.dropboxusercontent.com/u/152896/readme.pdf


[1]Pelican also has a large number of themes available; this blog is based on a mixture of the excellent Bootstrap-based BT3-Flat and Elegant.

Tags: pelican python