hexo-theme-stellar/layout/index.ejs

106 lines
3.0 KiB
Plaintext
Raw Permalink Normal View History

2021-02-19 23:33:19 +08:00
<%
2021-02-21 03:13:21 +08:00
if (page.menu_id == undefined) {
2021-02-19 23:33:19 +08:00
if (page.layout == 'index' && page.title && 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
function layout_post_card(type, post, content) {
var el = '';
el += '<a class="post-card ' + type + scrollreveal() + '" href="' + url_for(post.link || post.path) + '">';
el += '<article class="excerpt md">';
el += content;
el += '</article></a>';
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) {
var pinned = site.posts.filter(function(post){
return post.pin != undefined;
}).sort((config.index_generator && config.index_generator.order_by) || '-date');
pinned.forEach((post, i) => {
el += layout_post_card('post', post, partial(post));
});
}
// unpinned posts
page.posts.each(function(post){
if (post.pin == undefined) {
el += layout_post_card('post', post, partial(post));
}
})
} else {
el += '<h1 class="list-title">';
el += __('page.filter', config.title, page.category || page.tag, page.posts.length);
el += '</h1>';
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 = [];
if (page.title && page.wiki) {
// filtered wikis
page.wiki.forEach((wiki, i) => {
site.pages.filter(function (p) {
return p.layout == 'wiki' && p.wiki == wiki && p.description;
}).limit(1).each(function(post) {
wikis.push(post);
});
});
el += '<div class="post-list wiki filter">';
el += '<h1 class="list-title">' + __("page.wiki", config.title, wikis.length, page.title) + '</h1>';
wikis.forEach(function(wiki) {
el += layout_post_card('wiki', wiki, partial(wiki));
});
el += '</div>';
} else {
// all wikis
wikis = site.pages.filter(function (p) {
if (p.layout == 'wiki' && p.wiki && p.description) {
if (p.order == undefined) {
p.order = 0;
}
return true;
} else {
return false;
}
}).sort('order');
el += '<div class="post-list wiki">';
el += '<h1 class="list-title">' + __("page.wiki", config.title, wikis.length, __('btn.wiki')) + '</h1>';
wikis.forEach(function(wiki) {
el += layout_post_card('wiki', wiki, partial(wiki));
});
el += '</div>';
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-02-21 03:13:21 +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-02-21 03:13:21 +08:00
<% } else if (page.menu_id == 'wiki') { %>
2021-02-20 13:09:41 +08:00
<%- partial('_partial/main/navbar/list_wiki') %>
2021-02-27 17:15:47 +08:00
<%- layout_wikis(function(post){
return partial('_partial/main/post_list/wiki_card', {post: post})
}) %>
2021-02-19 23:33:19 +08:00
<% } %>