Friday, March 6, 2015

A better way to implement RSS feeds in SharePoint 2013/Online

image
I’m doing an assessment for migrating a 2010 solution to 2013, and one of the custom solutions installed was an RSS reader web part. We all know the RSS web part which came with 2010 is a bit limited, and it’s still there in 2013. So if you don’t have any requirements to do authentication on the RSS and you’re in love with XSLT, the web part is there for you my friend!

Another options is to use the Content Search Web Part. Yes CSWP indeed! SharePoint 2013/Online supports the creation of Result Sources using the OpenSearch 1.0/1.1 protocol. And the beauty of this protocol is that the response is in Atom or RSS format.
Below is a screenshot of setting up a result source to retrieve the latest news from CNN. I have also removed the query template as I won’t be doing a query – I just want the feed.

image

If you’re in need of authentication, then pick your poison at the bottom and you should be good to go.

The next part is using this in a CSWP.

image

Using the Picture on left, 3 lines on right template gives this view by default, which is not very pretty.

image

The only valuable data directly on the item is the Title property, but inside ctx.CurrentItem.OpenSearchSingleResultXML you will find what you’re looking for.

<item>
  <title>ISIS bulldozes cultural treasures of Nimrud</title>
  <guid>http://edition.cnn.com/2015/03/05/world/iraq-isis-destroys-ancient-city-nimrud/index.html</guid>
  <link>http://edition.cnn.com/2015/03/05/world/iraq-isis-destroys-ancient-city-nimrud/index.html?eref=edition</link>
  <description>Nimrud, the city of the Assyrian kingdom, has been destroyed by ISIS militants, Iraq's state-run media reports. </description>
  <pubDate>Fri, 06 Mar 2015 05:54:39 EST</pubDate>
  <media:thumbnail height="51" width="90" url="http://i2.cdn.turner.com/cnn/dam/assets/141028102122-middle-east-heritage-nimrud-top-tease.jpg" xmlns:media="http://search.yahoo.com/mrss/" />
  <media:content height="51" width="90" medium="image" type="image/jpeg" url="http://i2.cdn.turner.com/cnn/dam/assets/141028102122-middle-east-heritage-nimrud-top-tease.jpg" xmlns:media="http://search.yahoo.com/mrss/" />
</item>


The data might vary depending on your RSS feed, but I’ve created a sample RSS display template available on Github you can use for your modification. It will show the date and descriptions as line 2 and 3, and also pull out a thumbnail image.


image

You might also want to turn on caching on the CSWP – but not sure how it affects OpenSearch result sources.

image