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

48 lines
1.4 KiB
Plaintext

<%
function layoutDiv() {
var el = '';
el += '<div class="nav-wrap">';
el += '<nav class="sub wiki">';
// 所有项目
el += '<a';
if (page.filter === false) {
el += ' class="active"';
}
el += ' href="' + url_for(theme.site_tree.index_wiki.base_dir) + '">' + __("btn.all_wiki") + '</a>';
el += '</a>';
// 项目分类
const { shelf, all_tags } = theme.wiki;
for (let id of Object.keys(all_tags)) {
let tag = all_tags[id];
let projects = tag.items.filter(item => shelf.includes(item))
if (projects && projects.length > 0) {
el += '<a';
if (tag.name && tag.name.length > 0 && page.tagName === tag.name) {
el += ' class="active"';
}
el += ' href="' + url_for(tag.path) + '">' + tag.name + '</a>';
el += '</a>';
}
}
const { nav_tabs } = theme.site_tree.index_wiki
if (nav_tabs) {
for (let key of Object.keys(nav_tabs)) {
// 当 page 的末尾为 index.html 或者处于该 page 的某个子页面时也应该匹配
// if (full_url_for(page.path) == full_url_for(nav_tabs[key])) {
if (full_url_for(page.path).startsWith(full_url_for(nav_tabs[key]))){
el += '<a class="active" href="' + url_for(nav_tabs[key]) + '">' + key + '</a>';
} else {
el += '<a href="' + url_for(nav_tabs[key]) + '">' + key + '</a>';
}
}
}
el += '</nav>';
el += '</div>';
return el;
}
%>
<%- layoutDiv() %>