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

171 lines
7.8 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">';
2023-12-06 13:22:07 +08:00
el += '<div class="left">';
2021-07-26 22:26:46 +08:00
el += '<div id="breadcrumb">';
2023-12-13 10:30:39 +08:00
el += '<a class="cap breadcrumb" href="' + url_for(config.root) + '">' + home_title + '</a>';
2021-07-04 20:21:31 +08:00
el += '<span class="sep"></span>';
2023-12-13 10:30:39 +08:00
el += '<a class="cap breadcrumb" href="' + url_for(config.index_generator.path) + '">' + __("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>';
2024-01-04 22:50:57 +08:00
// 作者
var author = null
if (theme.authors) {
if (page.author?.length > 0 && theme.authors[page.author] != null) {
author = theme.authors[page.author]
} else {
author = theme.default_author
}
}
2021-07-04 20:21:31 +08:00
el += '<div id="post-meta">';
2024-01-04 22:50:57 +08:00
if (author) {
let link = `<a href="${url_for(author.path)}">${author.name}</a>`
el += `<span class="author">${__("meta.created_author", link)}</span>`
} else {
el += `<span class="author">${__("meta.created")}</span>`
}
// 发布日期
2023-12-06 13:22:29 +08:00
el += `
2024-01-04 22:50:57 +08:00
<span class="created"><time datetime="${date_xml(page.date)}">${date(page.date, config.date_format)}</time></span>
2023-12-06 13:22:29 +08:00
`;
2024-01-04 22:50:57 +08:00
// 更新日期
2023-12-06 13:22:29 +08:00
el += `
2024-01-04 22:50:57 +08:00
<span class="updated">${__("symbol.comma") + __("meta.updated")}&nbsp;<time datetime="${date_xml(page.updated)}">${date(page.updated, config.date_format)}</time></span>
2023-12-06 13:22:29 +08:00
`;
2021-07-04 20:21:31 +08:00
el += '</div>';
2023-12-06 13:22:29 +08:00
2021-07-26 22:26:46 +08:00
el += '</div>';
2023-12-06 13:22:07 +08:00
el += '</div>';
2024-01-14 14:10:36 +08:00
} else if (page.layout === 'topic' && page.topic?.length > 0) {
el += '<div class="bread-nav fs12">';
el += '<div class="left">';
el += '<div id="breadcrumb">';
var nodes = [];
// home
el += '<a class="cap breadcrumb" id="home" href="' + url_for(config.root) + '">' + home_title + '</a>';
nodes.push('/');
// menu_id
el += '<span class="sep"></span>';
let url = url_for(theme.base_dir.topic);
nodes.push(url);
el += '<a class="cap breadcrumb" id="menu" href="' + url + '">' + __("btn.topic") + '</a>';
// 专栏名
let topicObject = theme.topic.tree[page.topic];
if (topicObject != null) {
let url_proj = url_for(topicObject.homepage?.path);
if (nodes.includes(url_proj) === false) {
el += '<span class="sep"></span>';
el += '<a class="cap breadcrumb" id="proj" href="' + url_proj + '">' + (topicObject.name || topicObject.title) + '</a>';
}
}
el += '</div>';
// 更新日期
el += '<div id="post-meta">';
el += `
<span>${__("meta.updated")}&nbsp;<time datetime="${date_xml(page.updated)}">${date(page.updated, config.date_format)}</time></span>
`;
el += '</div>';
el += '</div>';
el += '</div>';
} else if (page.layout === "wiki" && page.wiki?.length > 0) {
2021-07-26 22:26:46 +08:00
el += '<div class="bread-nav fs12">';
2023-12-06 13:22:07 +08:00
el += '<div class="left">';
2021-07-26 22:26:46 +08:00
el += '<div id="breadcrumb">';
2021-07-04 20:21:31 +08:00
var nodes = [];
// home
2023-12-13 10:30:39 +08:00
el += '<a class="cap breadcrumb" id="home" href="' + url_for(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) {
2023-12-06 13:22:07 +08:00
let url_proj = url_for(proj.homepage?.path);
2023-12-06 13:20:04 +08:00
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">';
2023-12-06 13:22:29 +08:00
el += `
<span>${__("meta.updated")}&nbsp;<time datetime="${date_xml(page.updated)}">${date(page.updated, config.date_format)}</time></span>
`;
2021-07-04 20:21:31 +08:00
el += '</div>';
2021-07-26 22:26:46 +08:00
el += '</div>';
2023-12-06 13:22:07 +08:00
2024-01-04 10:22:05 +08:00
const repo = page.repo || proj?.repo
2023-12-06 13:22:07 +08:00
if (repo) {
el += `
<div class="right ghrepo stellar-ghinfo-api" api="${theme.api_host.ghapi}/repos/${repo}">
<a class="repo-link bold" href="https://github.com/${repo}">
<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1em" height="1em" fill="currentColor" style="user-select:none;overflow:visible"><path fill-rule="evenodd" d="M2 2.5A2.5 2.5 0 014.5 0h8.75a.75.75 0 01.75.75v12.5a.75.75 0 01-.75.75h-2.5a.75.75 0 110-1.5h1.75v-2h-8a1 1 0 00-.714 1.7.75.75 0 01-1.072 1.05A2.495 2.495 0 012 11.5v-9zm10.5-1V9h-8c-.356 0-.694.074-1 .208V2.5a1 1 0 011-1h8zM5 12.25v3.25a.25.25 0 00.4.2l1.45-1.087a.25.25 0 01.3 0L8.6 15.7a.25.25 0 00.4-.2v-3.25a.25.25 0 00-.25-.25h-3.5a.25.25 0 00-.25.25z"></path></svg>
<span type="text">${repo}</span>
</a>
<a class="repo-link" href="https://github.com/${repo}/stargazers">
<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1em" height="1em" fill="currentColor" style="user-select:none;overflow:visible"><path fill-rule="evenodd" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"></path></svg>
<span type="text" id="stargazers_count">0</span><span>stars</span>
</a>
<a class="repo-link" href="https://github.com/${repo}/forks">
<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1em" height="1em" fill="currentColor" style="user-select:none;overflow:visible"><path fill-rule="evenodd" d="M5 3.25a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm0 2.122a2.25 2.25 0 10-1.5 0v.878A2.25 2.25 0 005.75 8.5h1.5v2.128a2.251 2.251 0 101.5 0V8.5h1.5a2.25 2.25 0 002.25-2.25v-.878a2.25 2.25 0 10-1.5 0v.878a.75.75 0 01-.75.75h-4.5A.75.75 0 015 6.25v-.878zm3.75 7.378a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm3-8.75a.75.75 0 100-1.5.75.75 0 000 1.5z"></path></svg>
<span type="text" id="forks_count">0</span><span>forks</span>
</a>
</div>
`;
}
2021-07-26 22:26:46 +08:00
el += '</div>';
2023-12-06 13:22:07 +08:00
} else if (page.title || page.seo_title) {
el += `
<div class="bread-nav fs12">
<div class="left">
<div id="breadcrumb">
2023-12-13 10:30:39 +08:00
<a class="cap breadcrumb" href="${url_for(config.root)}">${home_title}</a>
2023-12-06 13:22:07 +08:00
<span class="sep"></span>
<a class="cap breadcrumb" href="${url_for(page.path)}">${page.title || page.seo_title}</a>
</div>
</div>
</div>
`;
2021-07-04 20:21:31 +08:00
}
return el;
}
%>
<%- layoutDiv() %>