Question

I can't figure out how to use feedr to parse a normal rss-feed like http://mashable.com/feed/.

How do I parse the feed? The documentation is quite poor. The twitter-example doesn't help me. For example I would like to grab a feed and show its content in a way like this:

<ul>
  <li><a href="link-to-posting">Post Title</a> – Post Content</li>
</ul>

Any suggestions?

Was it helpful?

Solution

The feedr plugin just turns any json or xml into a javascript object that you can use in pages. So with RSS feeds, you'll end up with an object that has properties that match the XML in the rss feed with elements becoming objects, etc. So there will be a channel object and then under that an array of item objects, etc...

Here's how your mashable example would work. Put this in the docpad.coffee configuration:

plugins:
    feedr:
        feeds:
            mashable:
                url: 'http://mashable.com/feed/'

Then, you can use the @feedr.feeds.mashable object in a page like this:

<ul>
    <% for item in @feedr.feeds.mashable.channel.item: %>
        <li><a href="<%= item.link %>"><%= item.title %></a> - <%- item.description %></li>
    <% end %>
</ul>

OTHER TIPS

If anyone else got trouble parsing... If you like to include a title, description and link to the parsed feed, add this snippet. This will add a linked title plus description.

<h1><a href="<%- @feedr.feeds.mashable.channel.link %>"><%= @feedr.feeds.mashable.channel.title %></a></h1>
<p><%= @feedr.feeds.mashable.channel.description %></p>

And than the rest like Erv mentioned above.

<ul>
    <% for item in @feedr.feeds.mashable.channel.item: %>
        <li><a href="<%= item.link %>"><%= item.title %></a> - <%- item.description %></li>
    <% end %>
</ul>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top