hexo-theme-stellar/layout/_partial/main/article/read_next.ejs

64 lines
1.8 KiB
Plaintext
Raw Normal View History

2021-02-20 13:09:41 +08:00
<%
function layoutDiv() {
2024-01-14 14:10:36 +08:00
var prev,next
var title = __('meta.read_next')
title_prev = __('meta.newer')
title_next = __('meta.older')
2024-01-18 22:11:58 +08:00
if (page.layout === 'post') {
2024-01-14 14:10:36 +08:00
prev = page.prev
next = page.next
2024-01-19 01:05:44 +08:00
} else if (page.wiki?.length > 0) {
2024-01-14 14:10:36 +08:00
var title_prev = __('meta.prev');
var title_next = __('meta.next');
2024-01-19 01:05:44 +08:00
const proj = theme.wiki.tree[page.wiki];
2021-07-26 22:26:46 +08:00
if (proj) {
2023-12-07 14:03:41 +08:00
let ps = proj.pages?.filter(p => p.path == page.path)
if (ps?.length > 0) {
2023-12-06 13:22:07 +08:00
const current_page_number = ps[0].page_number || 0;
proj.pages.forEach((p, i) => {
if (p.page_number < current_page_number) {
if (prev == undefined || p.page_number > prev.page_number) {
prev = p;
}
} else if (p.page_number > current_page_number) {
if (next == undefined || p.page_number < next.page_number) {
next = p;
}
2021-07-26 22:26:46 +08:00
}
2023-12-06 13:22:07 +08:00
});
} else {
console.error('未找到当前页');
}
2021-07-26 22:26:46 +08:00
}
2021-02-20 13:09:41 +08:00
}
2021-02-25 20:49:43 +08:00
let el = '';
2021-02-20 13:09:41 +08:00
if (prev || next) {
2024-01-19 01:05:44 +08:00
el += `<div class="related-wrap${scrollreveal(' ')}" id="read-next">`
2022-10-23 16:56:27 +08:00
el += '<section class="body">';
2022-10-24 23:30:34 +08:00
// prev
el += '<div class="item" id="prev">';
2021-02-20 13:09:41 +08:00
if (prev) {
2022-10-24 23:30:34 +08:00
el += '<div class="note">' + title_prev + '</div>';
el += '<a href="' + url_for(prev.path) + '">';
2024-01-18 12:33:12 +08:00
el += prev.title || prev.wiki || date(prev.date, config.date_format);
2021-06-26 12:40:13 +08:00
el += '</a>';
}
2022-10-24 23:30:34 +08:00
el += '</div>';
// next
el += '<div class="item" id="next">';
if (next) {
el += '<div class="note">' + title_next + '</div>';
el += '<a href="' + url_for(next.path) + '">';
2024-01-18 12:33:12 +08:00
el += next.title || next.wiki || date(next.date, config.date_format);
2022-10-24 23:30:34 +08:00
el += '</a>';
}
el += '</div>';
2021-02-25 20:49:43 +08:00
el += '</section>';
el += '</div>';
2021-02-20 13:09:41 +08:00
}
2021-02-25 20:49:43 +08:00
return el;
2021-02-20 13:09:41 +08:00
}
%>
<%- layoutDiv(); %>