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

88 lines
3.4 KiB
Plaintext
Raw Normal View History

2021-07-04 20:21:31 +08:00
<%
function layoutDiv() {
var el = '';
if (page.breadcrumb === false) {
return el;
}
2021-08-28 13:08:53 +08:00
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;
}
}
2021-07-04 20:21:31 +08:00
if (page.layout === "post") {
var firstCat = "";
2021-02-23 21:09:49 +08:00
if (page.categories && page.categories.length > 0) {
firstCat = page.categories.data[0].name;
}
2021-07-26 22:26:46 +08:00
el += '<div class="bread-nav fs12">';
el += '<div id="breadcrumb">';
2021-08-28 13:08:53 +08:00
el += '<a class="cap breadcrumb" href="' + config.root + '">' + home_title + '</a>';
2021-07-04 20:21:31 +08:00
el += '<span class="sep"></span>';
2021-08-28 13:08:53 +08:00
el += '<a class="cap breadcrumb" href="' + config.root + '">' + __("btn.blog") + '</a>';
2021-07-04 20:21:31 +08:00
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>';
2021-07-26 22:26:46 +08:00
el += '</div>';
2021-07-04 20:21:31 +08:00
} else if (page.layout === "wiki" && page.wiki && page.wiki.length > 0) {
2021-07-26 22:26:46 +08:00
el += '<div class="bread-nav fs12">';
el += '<div id="breadcrumb">';
2021-07-04 20:21:31 +08:00
var nodes = [];
// home
2021-08-28 13:08:53 +08:00
el += '<a class="cap breadcrumb" id="home" href="' + config.root + '">' + home_title + '</a>';
2021-07-04 20:21:31 +08:00
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>';
}
// 项目名
2023-12-06 13:20:04 +08:00
let proj = theme.wiki.tree[page.wiki];
if (proj != null) {
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.name || proj.title) + '</a>';
}
2021-07-04 20:21:31 +08:00
}
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>';
2021-07-26 22:26:46 +08:00
el += '</div>';
} else if (page.title || page.seo_title) {
el += '<div class="bread-nav fs12">';
2021-07-04 20:21:31 +08:00
el += '<div id="breadcrumb">';
2021-08-28 13:08:53 +08:00
el += '<a class="cap breadcrumb" href="' + config.root + '">' + home_title + '</a>';
2021-07-04 20:21:31 +08:00
el += '<span class="sep"></span>';
el += '<a class="cap breadcrumb" href="' + url_for(page.path) + '">' + (page.title || page.seo_title) + '</a>';
el += '</div>';
2021-07-26 22:26:46 +08:00
el += '</div>';
2021-07-04 20:21:31 +08:00
}
return el;
}
%>
<%- layoutDiv() %>