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

62 lines
1.9 KiB
Plaintext
Raw Normal View History

2021-03-13 13:32:45 +08:00
<%
function layoutDiv() {
2024-01-19 01:05:44 +08:00
var el = `<widget class="widget-wrapper${scrollreveal(' ')} post-list">`
2021-03-13 13:32:45 +08:00
// header
2024-01-17 22:57:52 +08:00
el += '<div class="widget-header dis-select">';
2021-03-13 13:32:45 +08:00
el += '<span class="name">' + __("meta.recent_update") + '</span>';
if (item.rss) {
el += '<a class="cap-action" id="rss" title="Subscribe" href="' + item.rss + '">';
2024-01-19 13:51:55 +08:00
el += icon('default:rss')
2021-03-13 13:32:45 +08:00
el += '</a>';
}
el += '</div>';
// body
2021-07-26 22:26:46 +08:00
var arr = [];
if (page.menu_id == 'wiki') {
2022-11-19 16:08:50 +08:00
arr = theme.wiki.all_pages.filter( p => {
2021-07-26 22:26:46 +08:00
if (p.wiki) {
2023-12-06 13:20:04 +08:00
let proj = theme.wiki.tree[p.wiki];
return proj?.index != false;
2021-07-26 22:26:46 +08:00
}
2022-11-19 16:08:50 +08:00
return false
})
2022-11-19 23:14:41 +08:00
arr = arr.sort((p1, p2) => p1.updated > p2.updated ? -1 : 1)
2024-05-13 09:45:38 +08:00
} else if (page.layout === 'notebooks') {
arr = site.pages.filter(p => p.notebook).sort('-updated')
} else if (page.notebook) {
arr = site.pages.filter(p => p.notebook === page.notebook).sort('-updated')
2021-07-26 22:26:46 +08:00
} else {
2022-11-19 16:08:50 +08:00
arr = site.posts.filter( p => p.title && p.title.length > 0)
2022-11-19 23:14:41 +08:00
arr = arr.sort("updated", -1)
2021-07-26 22:26:46 +08:00
}
2024-01-20 13:47:36 +08:00
el += '<div class="widget-body fs14">'
arr = arr.filter(p => p.title?.length > 0)
2022-11-19 16:08:50 +08:00
arr.length = item.limit
arr.forEach(post => {
2022-11-22 23:33:52 +08:00
if (!post) { return }
2024-02-07 16:21:19 +08:00
el += `<a class="item title" href="${url_for(post.link || post.path)}">`
2022-10-25 13:57:31 +08:00
el += '<span class="title">'
2024-01-19 01:05:44 +08:00
if (post.wiki) {
const proj = theme.wiki.tree[post.wiki];
2022-11-23 23:17:24 +08:00
let name = proj?.name || post?.wiki;
if (name) {
el += '<strong>' + name + '</strong>' + '<span class="dot"></span>';
2021-07-07 01:18:13 +08:00
}
2024-05-13 09:45:38 +08:00
} else if (page.layout === 'notebooks') {
const notebook = theme.notebooks.tree[post.notebook]
const name = notebook?.name || post.notebook
if (name) {
el += '<strong>' + name + '</strong>' + '<span class="dot"></span>';
}
2021-07-07 01:18:13 +08:00
}
2024-01-20 13:47:36 +08:00
el += post.title + '</span>';
2021-03-13 13:32:45 +08:00
el += '</a>';
el += '';
});
el += '</div>';
2022-11-23 21:54:21 +08:00
el += '</widget>';
2021-03-13 13:32:45 +08:00
return el;
}
%>
<%- layoutDiv() %>