Create RSS for Facebook's Instant Articles

A workaround, but it works:

  1. Create a dummy section:
mkdir content/instantarticles
  1. Add a dummy content file:
touch  content/dummy.md
  1. Create a layout according to FB’s spec in
layouts\section\instantarticles.rss.xml

This is a sample that can be used to create the template:

<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>News Publisher</title>
    <link>http://www.example.com/</link>
    <description>
        Read our awesome news, every day.    
    </description>
    <language>en-us</language>
    <lastBuildDate>2014-12-11T04:44:16Z</lastBuildDate>
    <item>
      <title>This is an Instant Article</title>
      <link>http://www.example.com/human-friendly-article-link</link>
      <guid>2fd4e1c67a2d28fced849ee1bb76e7391b93eb12</guid>
      <pubDate>2014-12-11T04:44:16Z</pubDate>
      <author>Mr. Author</author>
      <description>This is my first Instant Article. How awesome is this?</description>
      <content:encoded><![CDATA[
        (The full content of your article, in HTML form.)
      ]]></content:encoded>
    </item>
  </channel>
</rss>

I will add a more complete template when I get there …

3 Likes

I just created my own custom RSS feed for Instant Articles. I ran into an error. After some investigation it turned out that the content:encoded part is not rendered correctly.

The first “<” is rendered as “<” causing the following code to not working.

<content:encoded><![CDATA[

is rendered as

<content:encoded>&lt;![CDATA[

I found that issue in Hugo 0.15 and 0.17.

Unfortunately, instant articles only seem to work if they are provided as HTML part like described above.

Any ideas? Does anyone has successfully accomplished creating instant articles via RSS feed from Hugo?

Thanks!

@adcgn the little know chomp will take you there! Write it like this for correct CDATA-output:

<content:encoded>{{chomp "<![CDATA[\n"}}{{ .Content | safeHTML }}{{chomp "]]>\n"}}</content:encoded>

You will get an error viewing it directly in the browser, but the source is correctly formatted.

Thanks @Rick, that works quite well and saved me a lot of workarounds.

Cheers,
adcgn

No worries mate :slight_smile:

Also if you intend to use it for RSS, make sure to validate through W3C’s validator when you are done. Flipboard provides a great guide on how to format RSS