hexo-theme-stellar/layout/index.ejs

90 lines
2.5 KiB
Plaintext
Raw Normal View History

2021-02-19 23:33:19 +08:00
<%
2021-07-26 22:26:46 +08:00
if (page.menu_id == undefined) {
2022-11-29 22:25:02 +08:00
if (page.layout === 'wiki_index' && page.wiki) {
2021-02-21 03:13:21 +08:00
page.menu_id = 'wiki';
2021-02-19 23:33:19 +08:00
} else {
2021-02-21 03:13:21 +08:00
page.menu_id = 'post';
2021-02-19 23:33:19 +08:00
}
}
2021-02-21 13:44:11 +08:00
if (page.title && page.wiki) {
page.robots = 'noindex,follow';
}
2021-02-27 17:15:47 +08:00
2021-07-04 20:21:31 +08:00
function layout_post_card(layout, post, content) {
2021-02-27 17:15:47 +08:00
var el = '';
var layout = layout;
2022-11-05 00:13:32 +08:00
if (layout == 'post' && post.cover != undefined && post.poster != undefined) {
layout += ' photo';
}
2021-07-04 20:21:31 +08:00
el += '<a class="post-card ' + layout + ' ' + scrollreveal() + '" href="' + url_for(post.link || post.path) + '">';
2021-02-27 17:15:47 +08:00
el += content;
el += '</a>';
2021-02-27 17:15:47 +08:00
return el;
}
2023-12-17 19:39:23 +08:00
function layout_post_list(partial) {
2021-02-27 17:15:47 +08:00
var el = '';
el += '<div class="post-list post">';
2021-02-26 20:02:32 +08:00
if (is_home()) {
2021-02-27 17:15:47 +08:00
// pinned posts
if (page.current == 1) {
2022-11-19 16:08:50 +08:00
var pinned = site.posts.filter(post => post.pin != undefined).sort((config.index_generator && config.index_generator.order_by) || '-date');
2021-02-27 17:15:47 +08:00
pinned.forEach((post, i) => {
el += layout_post_card('post', post, partial(post));
});
}
// unpinned posts
page.posts.each(function(post){
2021-07-26 22:26:46 +08:00
if (post.pin == undefined) {
2021-02-27 17:15:47 +08:00
el += layout_post_card('post', post, partial(post));
}
})
} else {
page.posts.each(function(post){
el += layout_post_card('post', post, partial(post));
})
}
el += '</div>';
return el;
}
2023-12-17 19:39:23 +08:00
function layout_wiki_list(partial) {
2021-02-27 17:15:47 +08:00
var el = '';
2023-12-06 13:22:07 +08:00
const { shelf, tree } = theme.wiki;
for (let pid of shelf) {
let proj = tree[pid];
2023-12-06 13:20:04 +08:00
if (proj == null) {
continue;
}
2023-12-06 13:22:07 +08:00
if (proj.pages == undefined || proj.pages.length === 0) {
2021-07-04 20:21:31 +08:00
continue;
}
if (page.filter === false) {
2023-12-17 19:39:23 +08:00
// wikiList
2021-07-26 22:26:46 +08:00
el += '<div class="post-list wiki">';
el += layout_post_card('wiki', proj.homepage, partial(proj));
el += '</div>';
} else if (proj.tags && proj.tags.includes(page.tagName) === true) {
2023-12-17 19:39:23 +08:00
// filtered wikiList
2021-07-26 22:26:46 +08:00
el += '<div class="post-list wiki filter">';
el += layout_post_card('wiki', proj.homepage, partial(proj));
el += '</div>';
2021-07-04 20:21:31 +08:00
}
2021-02-26 20:02:32 +08:00
}
return el;
}
2021-02-19 23:33:19 +08:00
%>
2021-02-27 17:15:47 +08:00
2021-07-04 20:21:31 +08:00
<% if (page.menu_id === 'post') { %>
2021-02-20 13:09:41 +08:00
<%- partial('_partial/main/navbar/list_post') %>
2023-12-17 19:39:23 +08:00
<%- layout_post_list(function(post){
2021-02-27 17:15:47 +08:00
return partial('_partial/main/post_list/post_card', {post: post})
}) %>
<%- partial('_partial/main/post_list/paginator') %>
2021-07-04 20:21:31 +08:00
<% } else if (page.menu_id === 'wiki') { %>
2021-02-20 13:09:41 +08:00
<%- partial('_partial/main/navbar/list_wiki') %>
2023-12-17 19:39:23 +08:00
<%- layout_wiki_list(function(proj){
2021-07-04 20:21:31 +08:00
return partial('_partial/main/post_list/wiki_card', {proj: proj})
2021-02-27 17:15:47 +08:00
}) %>
2021-02-19 23:33:19 +08:00
<% } %>