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

47 lines
1.3 KiB
Plaintext
Raw Normal View History

2021-06-26 15:02:32 +08:00
<%
function layoutDiv() {
if (page.layout !== "wiki") {
return '';
}
2021-07-26 22:26:46 +08:00
var related = [];
2023-12-06 13:22:07 +08:00
const { shelf, tree } = theme.wiki;
let proj = tree[page.wiki];
2023-12-06 13:20:04 +08:00
if (proj?.related?.length > 0) {
2023-12-06 13:22:07 +08:00
proj.related.filter(pid => shelf.includes(pid)).forEach((pid, i) => {
let p = tree[pid];
if (p && p.title !== proj?.title) {
2021-07-26 22:26:46 +08:00
related.push(p);
}
});
}
var el = '';
if (related.length > 0) {
2022-11-23 21:54:21 +08:00
el += '<widget class="widget-wrapper related">';
2022-10-25 13:57:31 +08:00
el += '<div class="widget-header cap theme dis-select">';
2021-07-26 22:26:46 +08:00
var title = __('btn.wiki');
if (proj.tags && proj.tags[0]) {
title = proj.tags[0];
2021-07-04 20:21:31 +08:00
}
2021-07-26 22:26:46 +08:00
el += '<span class="name">' + __('meta.more', title) + '</span>';
el += '</div>';
2022-10-25 13:57:31 +08:00
el += '<div class="widget-body related-posts">';
2021-07-26 22:26:46 +08:00
related.forEach((p, i) => {
2023-12-06 13:22:07 +08:00
if (p.homepage == null) {
console.error("未找到首页:", p.title);
}
2021-07-26 22:26:46 +08:00
// 同一个分组中的其它项目
2023-12-06 13:22:07 +08:00
el += '<a class="item wiki" href="' + url_for(p.homepage?.path) + '">';
2022-10-25 13:57:31 +08:00
el += '<span class="title">' + p.title + '</span>';
if (p.description && p.description.length > 0) {
el += '<span class="excerpt">' + p.description + '</span>';
}
2021-07-26 22:26:46 +08:00
el += '</a>';
});
el += '</div>';
2022-11-23 21:54:21 +08:00
el += '</widget>';
2021-07-04 20:21:31 +08:00
}
2021-06-26 15:02:32 +08:00
return el;
}
%>
<%- layoutDiv() %>