hexo-theme-stellar/layout/_partial/main/navbar/breadcrumb.ejs

86 lines
3.3 KiB
Plaintext

<%
function layoutDiv() {
var el = '';
if (page.breadcrumb === false) {
return el;
}
var home_title = __("btn.home");
if (theme.breadcrumb && theme.breadcrumb.home) {
if (theme.breadcrumb.home === 'config.title') {
home_title = config.title;
} else if (theme.breadcrumb.home === 'config.author') {
home_title = config.author;
} else if (theme.breadcrumb.home !== 'home') {
home_title = theme.breadcrumb.home;
}
}
if (page.layout === "post") {
var firstCat = "";
if (page.categories && page.categories.length > 0) {
firstCat = page.categories.data[0].name;
}
el += '<div class="bread-nav fs12">';
el += '<div id="breadcrumb">';
el += '<a class="cap breadcrumb" href="' + config.root + '">' + home_title + '</a>';
el += '<span class="sep"></span>';
el += '<a class="cap breadcrumb" href="' + config.root + '">' + __("btn.blog") + '</a>';
if (page.layout == "post" && page.categories && page.categories.length > 0) {
el += '<span class="sep"></span>';
el += list_categories(page.categories, {
class: "cap breadcrumb",
show_count: false,
separator: ' <span class="sep"></span> ',
style: "none"
});
}
el += '</div>';
// 发布日期
el += '<div id="post-meta">';
el += __("meta.created") + '&nbsp;<time datetime="' + date_xml(page.date) + '">' + date(page.date, config.date_format) + '</time>';
el += '</div>';
el += '</div>';
} else if (page.layout === "wiki" && page.wiki && page.wiki.length > 0) {
el += '<div class="bread-nav fs12">';
el += '<div id="breadcrumb">';
var nodes = [];
// home
el += '<a class="cap breadcrumb" id="home" href="' + config.root + '">' + home_title + '</a>';
nodes.push('/');
// menu_id
el += '<span class="sep"></span>';
if (page.menu_id && theme.sidebar.menu[page.menu_id] && md_link(theme.sidebar.menu[page.menu_id])) {
let url = url_for(md_link(theme.sidebar.menu[page.menu_id]));
nodes.push(url);
el += '<a class="cap breadcrumb" id="menu" href="' + url + '">' + __(md_text(theme.sidebar.menu[page.menu_id])) + '</a>';
} else {
let url = url_for(config.wiki_dir || "/wiki/");
nodes.push(url);
el += '<a class="cap breadcrumb" id="menu" href="' + url + '">' + __("btn.wiki") + '</a>';
}
// 项目名
let proj = theme.wiki.projects[page.wiki];
let url_proj = url_for(proj.homepage.path);
if (nodes.includes(url_proj) === false) {
el += '<span class="sep"></span>';
el += '<a class="cap breadcrumb" id="proj" href="' + url_proj + '">' + proj.title + '</a>';
}
el += '</div>';
// 更新日期
el += '<div id="post-meta">';
el += __("meta.updated") + '&nbsp;<time datetime="' + date_xml(page.updated) + '">' + date(page.updated, config.date_format) + '</time>';
el += '</div>';
el += '</div>';
} else if (page.title || page.seo_title) {
el += '<div class="bread-nav fs12">';
el += '<div id="breadcrumb">';
el += '<a class="cap breadcrumb" href="' + config.root + '">' + home_title + '</a>';
el += '<span class="sep"></span>';
el += '<a class="cap breadcrumb" href="' + url_for(page.path) + '">' + (page.title || page.seo_title) + '</a>';
el += '</div>';
el += '</div>';
}
return el;
}
%>
<%- layoutDiv() %>