문제

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?

도움이 되었습니까?

해결책

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>

다른 팁

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top