hexo-theme-stellar/layout/index.ejs

88 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) {
2021-07-04 20:21:31 +08:00
if (page.layout === '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;
}
function layout_posts(partial) {
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;
}
function layout_wikis(partial) {
var el = '';
var wikis = [];
2021-07-04 20:21:31 +08:00
const projects = theme.wiki.projects;
for (let proj_name of Object.keys(projects)) {
let proj = projects[proj_name];
2021-07-26 22:26:46 +08:00
if (proj.index === false || proj.pages == undefined || proj.pages.length === 0) {
2021-07-04 20:21:31 +08:00
continue;
}
if (page.filter === false) {
// all wikis
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) {
2021-07-04 20:21:31 +08:00
// filtered wikis
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') %>
2021-02-27 17:15:47 +08:00
<%- layout_posts(function(post){
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') %>
2021-07-04 20:21:31 +08:00
<%- layout_wikis(function(proj){
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
<% } %>