hexo-theme-stellar/layout/_partial/widgets/recent.ejs

55 lines
1.5 KiB
Plaintext

<%
function layoutDiv() {
var el = `<widget class="widget-wrapper${scrollreveal(' ')} post-list">`
// header
el += '<div class="widget-header dis-select">';
el += '<span class="name">' + __("meta.recent_update") + '</span>';
if (item.rss) {
el += '<a class="cap-action" id="rss" title="Subscribe" href="' + item.rss + '">';
el += icon('default:rss')
el += '</a>';
}
el += '</div>';
// body
var arr = [];
if (page.menu_id == 'wiki') {
arr = theme.wiki.all_pages.filter( p => {
if (p.wiki) {
let proj = theme.wiki.tree[p.wiki];
return proj?.index != false;
}
return false
})
arr = arr.sort((p1, p2) => p1.updated > p2.updated ? -1 : 1)
} else {
arr = site.posts.filter( p => p.title && p.title.length > 0)
arr = arr.sort("updated", -1)
}
el += '<div class="widget-body fs14">';
arr.length = item.limit
arr.forEach(post => {
if (!post) { return }
const isActive = post.path == page.path
el += `<a class="item title${post.path == page.path ? ' active' : ''}" href="${url_for(post.link || post.path)}">`
el += '<span class="title">'
if (post.wiki) {
const proj = theme.wiki.tree[post.wiki];
let name = proj?.name || post?.wiki;
if (name) {
el += '<strong>' + name + '</strong>' + '<span class="dot"></span>';
}
}
el += (post.title || post.wiki) + '</span>';
if (isActive) {
el += icon('default:bookmark')
}
el += '</a>';
el += '';
});
el += '</div>';
el += '</widget>';
return el;
}
%>
<%- layoutDiv() %>