<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:media="http://purl.org/syndication/atommedia" xmlns:ostatus="http://ostatus.org/schema/1.0">
  <id><%= href('/feed.atom') %></id>
  <title><%= site.title %></title>
  <updated><%= moment().format() %></updated>
  <% if (site.description) { %>
   <subtitle><%= site.description  %></subtitle>
  <% } %>
  <% if (site.avatar) { %>
   <logo><%= href(site.avatar) %></logo>
  <% } %>

  <author>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <uri><%= href('/') %></uri>
    <name><%= site.authorName %></name>
    <% if (site.avatar) {%>
    <link rel="avatar" type="<%= mime.lookup(site.avatar) %>" media:width="120" media:height="120" href="<%= href(site.avatar) %>"/>
    <% } %>
    <poco:displayName><%= site.authorName %></poco:displayName>
    <poco:note><%= site.description  %></poco:note>
  </author>
  
  <link rel="alternate" type="text/html" href="<%= href('/') %>"/>
  <link rel="self" type="application/atom+xml" href="<%= href('./atom.xml') %>"/>

  <% if (page < nPages){ %>
    <link rel="next" type="application/atom+xml" href="<%= href('./atom/'+(page+1)+'.xml') %>"/>
  <% } %>
  <% if (page > 1){ %>
    <% if (page == 2){ %>    
      <link rel="previous" type="application/atom+xml" href="<%= href('./atom/feed.xml') %>"/>
    <% } else { %>
      <link rel="previous" type="application/atom+xml" href="<%= href('./atom/'+(page-1)+'.xml') %>"/>
    <% } %>
  <% } %>
  <link rel="first" type="application/atom+xml" href="<%= href('./atom/feed.xml') %>"/>
  <link rel="last" type="application/atom+xml" href="<%= href('./atom/'+nPages+'.xml') %>"/>


  <% for (var i = 0; i < posts.length; i ++ ){%>
    <%  var post = posts[i];  %>
    <entry>
      <id><%= href(post.permalink) %></id>
      <published><%= post.date %></published>
      <updated><%= post.date %></updated>
      <title><%= post.title || "New Post on "+site.title %></title>
      <content type="html" xml:lang="en"><%= post.rawHtml %></content>
      <% for (var j = 0; j < post.assets.length; j ++){  %>
        <% var e=post.assets[j] %>
        <link rel="enclosure" type="<%= e.mimetype %>" href="<%= href(e.href) %>"/>
      <% } %>
      <% for (var j = 0; j < post.tags.length; j ++){  %>
        <category term="<%= post.tags[j] %>"/>
      <% } %>
      <link rel="alternate" type="text/html" href="<%= href(post.permalink) %>"/>
    </entry>
  <% } %>
</feed>
