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

48 lines
1.4 KiB
Plaintext
Raw Normal View History

2021-07-04 20:21:31 +08:00
<%
function layoutDiv() {
var el = '';
2021-08-19 23:13:05 +08:00
el += '<div class="nav-wrap">';
2021-07-04 20:21:31 +08:00
el += '<nav class="sub wiki cap">';
// 所有项目
el += '<a';
if (page.filter === false) {
el += ' class="active"';
}
2024-01-20 01:51:09 +08:00
el += ' href="' + url_for(theme.site_tree.index_wiki.base_dir) + '">' + __("btn.all_wiki") + '</a>';
2021-07-04 20:21:31 +08:00
el += '</a>';
// 项目分类
2023-12-06 13:22:07 +08:00
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))
2021-07-04 20:21:31 +08:00
if (projects && projects.length > 0) {
el += '<a';
2021-07-26 22:26:46 +08:00
if (tag.name && tag.name.length > 0 && page.tagName === tag.name) {
2021-07-04 20:21:31 +08:00
el += ' class="active"';
2021-02-20 13:09:41 +08:00
}
2021-07-26 22:26:46 +08:00
el += ' href="' + url_for(tag.path) + '">' + tag.name + '</a>';
2021-07-04 20:21:31 +08:00
el += '</a>';
2021-07-08 22:23:55 +08:00
}
2021-07-04 20:21:31 +08:00
}
2024-01-14 16:42:20 +08:00
2024-01-20 01:51:09 +08:00
const { nav_tabs } = theme.site_tree.index_wiki
2024-01-14 16:42:20 +08:00
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>';
}
}
}
2021-07-04 20:21:31 +08:00
el += '</nav>';
el += '</div>';
return el;
}
%>
<%- layoutDiv() %>