<% function pad(n) { -%>
<%   return +n < 10 ? '0' + n : String(n) -%>
<% } -%>

<% var _months = 'January February March April May June July August September October November December'.split(' ') -%>
<% var _shortMonths = _months.map(function(m) { return m.slice(0, 3) }) -%>
<% function formatDate(t) { -%>
<%   var d = new Date(t) -%>
<%   return d.getDate() + ' ' + _shortMonths[d.getMonth()] -%>
<% } -%>

<% function sortPosts(dir) { -%>
<%   var slugs = Object.keys(dir._data) -%>
<%   var posts = slugs.map(function(slug) { -%>
<%     var d = dir._data[slug]; -%>
<%     d.slug = slug; -%>
<%     return d; -%>
<%   }) -%>
<%   posts.sort(function(a, b) { -%>
<%     var t1 = a.timestamp -%>
<%     var t2 = b.timestamp -%>
<%     return t1 < t2 ? 1 : (t1 > t2 ? -1 : 0) -%>
<%   }) -%>
<%   return posts -%>
<% } -%>

<% var posts = sortPosts(public.posts[current.path[1]][current.path[2]]) -%>
<% for (var i in posts) { -%>
<%   var post = posts[i] -%>
<%   if (post.hidden) continue -%>

    <article class="container">
      <header>
<%   if (post.link) { -%>
        <h2><a href="<%= post.link %>">&rarr; <%= post.title %></a></h2>
        <time><%= post.date %></time>
        <a class="permalink" href="<%= post.url %>">&infin;</a>
<%   } else { -%>
        <h2><a href="<%= post.url %>"><%= post.title %></a></h2>
        <time><%= post.date %></time>
<%   } -%>

      </header>

      <%- partial(current.path[1] + '/' + current.path[2] + '/' + post.slug) %>
    </article>

    <div class="row clearfix">
      <p class="fin"><i class="fa fa-code"></i></p>
    </div>

<% } -%>
