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

44 lines
1.2 KiB
Plaintext

<%
function layoutDiv() {
if (page.layout !== "wiki") {
return '';
}
var related = [];
const { shelf, tree } = theme.wiki;
let proj = tree[page.wiki];
if (proj?.related?.length > 0) {
proj.related.filter(pid => shelf.includes(pid)).forEach((pid, i) => {
let p = tree[pid];
if (p && p.title !== proj?.title && p.homepage) {
related.push(p);
}
});
}
var el = '';
if (related.length > 0) {
el += '<widget class="widget-wrapper related">';
el += '<div class="widget-header cap theme dis-select">';
var title = __('btn.wiki');
if (proj.tags && proj.tags[0]) {
title = proj.tags[0];
}
el += '<span class="name">' + __('meta.more', title) + '</span>';
el += '</div>';
el += '<div class="widget-body related-posts">';
for (let p of related) {
// 同一个分组中的其它项目
el += '<a class="item wiki" href="' + url_for(p.homepage?.path) + '">';
el += '<span class="title">' + p.title + '</span>';
if (p.description && p.description.length > 0) {
el += '<span class="excerpt">' + p.description + '</span>';
}
el += '</a>';
}
el += '</div>';
el += '</widget>';
}
return el;
}
%>
<%- layoutDiv() %>