archive.pug 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. extends layout
  2. //- this logic should be moved to a view at some point
  3. block content
  4. - var lineHeight = 2.2;
  5. - var archives = _.chain(env.helpers.getArticles(contents)).groupBy(function(item) {
  6. - return item.date.getFullYear();
  7. - }).value();
  8. - for (var archive in archives) {
  9. - archives[archive] = _.groupBy(archives[archive], function(item) { return item.date.getMonth(); });
  10. - }
  11. - var month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
  12. section.archive
  13. h2 Archive
  14. ul
  15. - var yearsK = _.chain(archives).keys().reverse().value();
  16. each yearK in yearsK
  17. - var months = archives[yearK];
  18. - var yearHeight = lineHeight * _.reduce(months, function(memo,month) { return memo + month.length; }, 0);
  19. li
  20. span.year-label(style='line-height:' + yearHeight + 'em')= yearK
  21. ul(style='margin-left:4em')
  22. - var monthsK = _.chain(months).keys().reverse().value();
  23. each monthK in monthsK
  24. - var monthHeight = lineHeight * months[monthK].length;
  25. li
  26. span.month-label(style='line-height:' + monthHeight + 'em')= month_names[monthK]
  27. ul(style='margin-left:7em')
  28. each item in months[monthK]
  29. li(style='height:'+ lineHeight + 'em;line-height:' + lineHeight + 'em')
  30. a(href=item.url)= item.title