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

66 lines
1.9 KiB
Plaintext
Raw Normal View History

2021-06-26 15:02:32 +08:00
<%
2024-01-14 14:10:36 +08:00
function relatedPostsInTopic() {
if (page.topic?.length == 0) {
return ''
}
const topic = theme.topic.tree[page.topic]
if (topic == null) {
return ''
}
var el = ''
2024-01-19 01:05:44 +08:00
el += `<widget class="widget-wrapper${scrollreveal(' ')} post-list">`
2024-01-17 22:57:52 +08:00
el += `<div class="widget-header dis-select">`
2024-02-01 21:27:34 +08:00
el += `<span class="name">${__('btn.topic') + __('symbol.colon') + (topic.name || topic.title)}</span>`
2024-01-14 14:10:36 +08:00
el += `</div>`
2024-01-17 00:27:48 +08:00
el += `<div class="widget-body">`
2024-01-14 14:10:36 +08:00
for (let post of topic.pages) {
2024-01-17 00:27:48 +08:00
const isActive = post.path == page.path
el += `<a class="item${isActive ? ' active' : ''}" href="${url_for(post.path)}">`
2024-01-14 14:10:36 +08:00
el += `<span class="title">${post.title}</span>`
2024-01-17 00:27:48 +08:00
if (isActive) {
2024-01-20 13:35:43 +08:00
el += icon('default:bookmark.active')
2024-01-17 00:27:48 +08:00
}
2024-01-14 14:10:36 +08:00
el += `</a>`
}
el += `</div>`
el += `</widget>`
return el
}
2024-01-13 21:10:26 +08:00
function relatedWiki() {
let thisItemObject = theme.wiki.tree[page.wiki]
2023-12-17 19:39:23 +08:00
if (thisItemObject == null) {
2024-01-13 21:10:26 +08:00
return ''
2021-07-26 22:26:46 +08:00
}
2024-01-13 21:10:26 +08:00
const relatedItems = thisItemObject.relatedItems
var el = ''
2023-12-17 19:39:23 +08:00
for (let relatedItem of relatedItems) {
2024-01-19 01:05:44 +08:00
el += `<widget class="widget-wrapper${scrollreveal(' ')} post-card">`
2024-01-17 22:57:52 +08:00
el += `<div class="widget-header dis-select">`
2024-01-14 18:50:15 +08:00
el += `<span class="name">${__('meta.more') + __('symbol.colon') + relatedItem.name}</span>`
2024-01-13 21:10:26 +08:00
el += `</div>`
2024-01-17 00:27:48 +08:00
el += `<div class="widget-body">`
2023-12-17 19:39:23 +08:00
for (let id of relatedItem.items) {
2021-07-26 22:26:46 +08:00
// 同一个分组中的其它项目
2024-01-13 21:10:26 +08:00
let item = theme.wiki.tree[id]
el += `<a class="item wiki" href="${url_for(item.homepage?.path)}">`
el += `<span class="title">${item.title}</span>`
2023-12-17 19:39:23 +08:00
if (item.description && item.description.length > 0) {
2024-01-13 21:10:26 +08:00
el += `<span class="excerpt">${item.description}</span>`
2022-10-25 13:57:31 +08:00
}
2024-01-13 21:10:26 +08:00
el += `</a>`
2023-12-07 14:03:41 +08:00
}
2024-01-13 21:10:26 +08:00
el += `</div>`
el += `</widget>`
}
return el
}
function layoutDiv() {
2024-01-18 22:11:58 +08:00
if (page.wiki?.length > 0) {
2024-01-13 21:10:26 +08:00
return relatedWiki()
2024-01-18 22:11:58 +08:00
} else if (page.topic?.length > 0) {
2024-01-14 14:10:36 +08:00
return relatedPostsInTopic()
2021-07-04 20:21:31 +08:00
}
2021-06-26 15:02:32 +08:00
}
%>
<%- layoutDiv() %>