2018-06-04 17:31:48 +08:00

80 lines
3.1 KiB
Plaintext

<%
var title = '';
var archiveHtml = null;
if (page.category) {
titleKey = 'categories';
archiveHtml = '<a class="breadcrumb" href="/' + page.base + '">' + page.category + '</a>';
}
if (page.tag) {
titleKey = 'tags';
archiveHtml = '<a class="breadcrumb" href="/' + page.base + '">' + page.tag + '</a>';
}
if (page.archive){
if (page.year) {
title = page.year + (page.month ? '/' + page.month : '');
} else {
titleKey = 'archives';
}
}
%>
<%- partial('pagenav', {nav_head: __('current_page') + __('page_name.' + titleKey), partial_path: null, archive_html: archiveHtml}) %>
<% if (pagination == 2){ %>
<% page.posts.each(function(item){ %>
<%- partial('simple_article', {item: item, index: true, showEntry: false, showTags: false}) %>
<% }); %>
<%- partial('pagination') %>
<% } else if (page.archive) { %>
<ul class="collapsible mt-0" data-collapsible="accordion">
<%
// 将各年份的文章汇总,数据结构为
// [{year: 2016, posts: [item1, item2]}, {year: 2015, posts: [item3, item4, item5]}]
var activeFlag = true;
var yearPosts = [];
page.posts.each(function(item) {
var y = item.date.year();
var yp;
if (yearPosts.length == 0 || yearPosts[yearPosts.length - 1].year != y) {
yp = {
year: y,
posts: [item]
};
yearPosts.push(yp);
} else {
yp = yearPosts[yearPosts.length - 1];
yp.posts.push(item);
}
});
%>
<% yearPosts.forEach(function(yearPost) { %>
<li>
<div class="collapsible-header <%= activeFlag ? 'active' : '' %><% activeFlag = false; %>">
<i class="fa fa-archive"></i><%= yearPost.year %>
</div>
<div class="collapsible-body">
<div class="collection">
<% yearPost.posts.forEach(function(item) { %>
<a href="<%- url_for(item.path) %>" class="collection-item <%= theme.color.archive_item %>-text text-darken-1">
<time datetime="<%= item.date.toDate().toISOString() %>"><%= item.date.format(config.date_format) %></time>
<span>&nbsp;&nbsp;&nbsp;</span>
<%- item.title %>
</a>
<% }); %>
</div>
</div>
</li>
<% }); %>
</ul>
<% } else { %>
<div class="collection mt-0">
<% page.posts.each(function(item) { %>
<a href="<%- url_for(item.path) %>" class="collection-item <%= theme.color.archive_item %>-text text-darken-1">
<time datetime="<%= item.date.toDate().toISOString() %>"><%= item.date.format(config.date_format) %></time>
<span>&nbsp;&nbsp;&nbsp;</span>
<%- item.title %>
</a>
<% }); %>
</div>
<% } %>