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

85 lines
2.6 KiB
Plaintext
Raw Normal View History

2021-06-26 15:02:32 +08:00
<%
2024-01-13 21:10:26 +08:00
function relatedPosts() {
const { categories } = page;
if (categories.length == 0) {
return ''
2021-06-26 15:02:32 +08:00
}
2024-01-13 21:10:26 +08:00
const relatedItem = categories.data[0]
var el = ''
el += `<widget class="widget-wrapper recent">`
el += `<div class="widget-header cap theme dis-select">`
2024-01-14 14:10:36 +08:00
el += `<span class="name">${__('btn.topic') + __('symbol.colon') + relatedItem.name}</span>`
2024-01-13 21:10:26 +08:00
el += `</div>`
el += `<div class="widget-body related-posts">`
relatedItem.posts.sort('date', -1).each(function(post) {
el += `<a class="item${post.path == page.path ? ' active' : ''}" href="${url_for(post.path)}">`
el += `<span class="title">${post.title}</span>`
el += `</a>`
})
el += `</div>`
el += `</widget>`
return el
}
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 = ''
el += `<widget class="widget-wrapper recent">`
el += `<div class="widget-header cap theme dis-select">`
el += `<span class="name">${__('btn.topic') + __('symbol.colon') + topic.name}</span>`
el += `</div>`
el += `<div class="widget-body related-posts">`
for (let post of topic.pages) {
el += `<a class="item${post.path == page.path ? ' active' : ''}" href="${url_for(post.path)}">`
el += `<span class="title">${post.title}</span>`
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-13 21:10:26 +08:00
el += `<widget class="widget-wrapper related">`
el += `<div class="widget-header cap theme dis-select">`
el += `<span class="name">${__('meta.more', relatedItem.name)}</span>`
el += `</div>`
el += `<div class="widget-body related-posts">`
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() {
if (page.layout == 'wiki') {
return relatedWiki()
} else if (page.layout == 'post') {
return relatedPosts()
2024-01-14 14:10:36 +08:00
} else if (page.layout == 'topic') {
return relatedPostsInTopic()
2021-07-04 20:21:31 +08:00
}
2021-06-26 15:02:32 +08:00
}
%>
<%- layoutDiv() %>