<?xml version="1.0" encoding="UTF-8"?>
<% coder = HTMLEntities.new %>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title><%= Rails.application.name %><%= @title.present? ?
      ": " + h(@title) : "" %></title>
    <description><%= @title %></description>
    <link><%= Rails.application.root_url + (@newest ? "newest" : "") %></link>
    <atom:link href="<%= request.original_url %>" rel="self" type="application/rss+xml" />

    <% @stories.each do |story| %>
      <item>
        <title><%= raw coder.encode(story.title, :decimal) %></title>
        <link><%= story.url_or_comments_url %></link>
        <guid isPermaLink="false"><%= story.short_id_url %></guid>
        <author><%= story.user.username %>@users.<%= Rails.application.domain %> (<%= story.user.username %>)</author>
        <pubDate><%= story.created_at.rfc2822 %></pubDate>
        <comments><%= story.comments_url %></comments>
        <description>
          <%= raw coder.encode(story.markeddown_description, :decimal) %>
          <% if story.url.present? %>
            <%= raw coder.encode("<p>" +
              link_to("Comments", story.comments_url) + "</p>", :decimal) %>
          <% end %>
        </description>
        <% story.taggings.each do |tagging| %>
          <category><%= tagging.tag.tag %></category>
        <% end %>
      </item>
    <% end %>
  </channel>
</rss>
