目录树分组
This commit is contained in:
parent
dbc4eaa135
commit
b9f3766833
|
@ -3,8 +3,13 @@
|
|||
if (page.sidebar == undefined) {
|
||||
if (page.layout == 'post' && page.content) {
|
||||
page.sidebar = ['toc', 'repo_info'];
|
||||
} else if (page.layout == 'wiki' && page.content) {
|
||||
page.sidebar = ['toc', 'repo_info', 'wiki_more'];
|
||||
} else if (page.layout == 'wiki' && page.content && page.wiki) {
|
||||
let proj = theme.wiki.projects[page.wiki];
|
||||
if (proj.sidebar) {
|
||||
page.sidebar = proj.sidebar;
|
||||
} else {
|
||||
page.sidebar = ['toc', 'repo_info', 'wiki_more'];
|
||||
}
|
||||
} else {
|
||||
page.sidebar = theme.sidebar.widgets.default_layout;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<%
|
||||
let proj = theme.wiki.projects[page.wiki];
|
||||
|
||||
function layoutToc() {
|
||||
if (toc(page.content).length > 0) {
|
||||
return toc(page.content, {
|
||||
|
@ -9,79 +11,91 @@ function layoutToc() {
|
|||
}
|
||||
return '';
|
||||
}
|
||||
function layoutDiv(fallback) {
|
||||
var t = '';
|
||||
if (page.layout == 'post' && page.content) {
|
||||
let toc_content = toc(page.content);
|
||||
if (toc_content && toc_content.length > 0) {
|
||||
t = page.layout;
|
||||
}
|
||||
} else if (page.layout == 'wiki') {
|
||||
t = page.layout;
|
||||
} else if (page.sidebar.includes('toc') == true) {
|
||||
t = page.layout;
|
||||
}
|
||||
|
||||
function layoutTocHeader(title) {
|
||||
var el = '';
|
||||
if (t.length > 0) {
|
||||
el += '<div class="widget-wrap" id="toc">';
|
||||
el += '<div class="widget-header cap dis-select">';
|
||||
if (page.toc_title) {
|
||||
el += '<span class="name">' + page.toc_title + '</span>';
|
||||
} else if (t == 'wiki') {
|
||||
el += '';
|
||||
} else {
|
||||
el += '<span class="name">' + __("meta.toc") + '</span>';
|
||||
el += '<div class="widget-header cap dis-select">';
|
||||
if (title) {
|
||||
el += '<span class="name">' + title + '</span>';
|
||||
} else {
|
||||
el += '<span class="name">' + __("meta.toc") + '</span>';
|
||||
}
|
||||
el += '</div>';
|
||||
return el;
|
||||
}
|
||||
|
||||
function layoutDocTree(pages) {
|
||||
var el = '';
|
||||
pages.forEach((p, i) => {
|
||||
let isActive = '';
|
||||
if (p.path === page.path) {
|
||||
isActive += ' active';
|
||||
}
|
||||
el += '<div class="doc-tree' + isActive + '">';
|
||||
if (proj.pages.length > 1) {
|
||||
el += '<a class="doc-tree-link' + isActive + '" href="' + url_for(p.path) + '">';
|
||||
el += '<span class="toc-text">' + (p.title || p.seo_title) + '</span>';
|
||||
el += '</a>';
|
||||
}
|
||||
if (p.path === page.path) {
|
||||
el += layoutToc();
|
||||
}
|
||||
el += '</div>';
|
||||
el += '<div class="widget-body fs14 ' + t + '">';
|
||||
if (page.layout == "wiki" && page.wiki) {
|
||||
var wikis = [];
|
||||
wikis = site.pages.filter(function (p) {
|
||||
if (p.layout == "wiki" && p.wiki && p.wiki == page.wiki && (p.title || p.seo_title)) {
|
||||
if (p.order == undefined) {
|
||||
p.order = 0;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}).sort("order");
|
||||
if (wikis.length > 1) {
|
||||
wikis.each(function(p) {
|
||||
let isActive = '';
|
||||
if (p.path == page.path) {
|
||||
isActive += ' active';
|
||||
}
|
||||
el += '<div class="doc-tree' + isActive + '">';
|
||||
el += '<a class="doc-tree-link' + isActive + '" href="' + url_for(p.path) + '">';
|
||||
el += '<span class="toc-text">' + (p.title || p.seo_title) + '</span>';
|
||||
el += '</a>';
|
||||
if (p.path == page.path) {
|
||||
el += layoutToc();
|
||||
}
|
||||
el += '</div>';
|
||||
});
|
||||
} else {
|
||||
el += '<div class="doc-tree active">';
|
||||
el += layoutToc();
|
||||
el += '</div>';
|
||||
}
|
||||
});
|
||||
return el;
|
||||
}
|
||||
|
||||
|
||||
function layoutDiv(fallback) {
|
||||
var type = '';
|
||||
if (proj && proj.pages) {
|
||||
if (proj.pages.length > 1) {
|
||||
type = 'multi';
|
||||
} else {
|
||||
type = 'single';
|
||||
}
|
||||
} else {
|
||||
let toc_content = toc(page.content);
|
||||
if (toc_content && toc_content.length > 0) {
|
||||
type = 'single';
|
||||
}
|
||||
}
|
||||
|
||||
var el = '';
|
||||
if (type.length > 0) {
|
||||
el += '<div class="widget-wrap" id="toc">';
|
||||
if (page.layout !== 'wiki') {
|
||||
// post 布局
|
||||
el += layoutTocHeader(page.toc_title || __("meta.toc"));
|
||||
el += '<div class="widget-body fs14 ' + type + '">';
|
||||
el += '<div class="doc-tree active">';
|
||||
el += layoutToc();
|
||||
el += '</div>';
|
||||
el += '</div>';
|
||||
} else if (proj) {
|
||||
// wiki 布局
|
||||
if (proj.sections && proj.sections.length > 0) {
|
||||
proj.sections.forEach((sec, i) => {
|
||||
// 多 section
|
||||
el += layoutTocHeader(sec.title);
|
||||
el += '<div class="widget-body fs14 ' + type + '">';
|
||||
el += layoutDocTree(sec.pages);
|
||||
el += '</div>';
|
||||
});
|
||||
} else {
|
||||
// 单 section
|
||||
el += '<div class="widget-body fs14 ' + type + '">';
|
||||
el += layoutDocTree(proj.pages);
|
||||
el += '</div>';
|
||||
}
|
||||
}
|
||||
el += '</div>';
|
||||
el += '</div>';
|
||||
return el;
|
||||
} else if (item.fallback) {
|
||||
return fallback(item.fallback);
|
||||
el += partial(item.fallback, {item: theme.sidebar.widgets[item.fallback]});
|
||||
}
|
||||
return el;
|
||||
}
|
||||
|
||||
%>
|
||||
<%-
|
||||
layoutDiv(function(widget){
|
||||
return partial(widget, {item: theme.sidebar.widgets[widget]})
|
||||
})
|
||||
%>
|
||||
|
||||
<%- layoutDiv() %>
|
||||
|
|
|
@ -67,6 +67,34 @@ module.exports = hexo => {
|
|||
proj.pages.limit(1).forEach((p, i) => {
|
||||
proj.path = p.path;
|
||||
});
|
||||
// 内页按 section 分组
|
||||
var secs = [];
|
||||
if (proj.sections) {
|
||||
for (let t of Object.keys(proj.sections)) {
|
||||
let range = proj.sections[t];
|
||||
if (range.length > 1) {
|
||||
secs.push({
|
||||
title: t,
|
||||
from: range[0],
|
||||
to: range[1]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
var newSections = [];
|
||||
secs.forEach((sec, i) => {
|
||||
const pages = proj.pages.filter(function (p) {
|
||||
return p.order >= sec.from && p.order <= sec.to;
|
||||
});
|
||||
if (pages && pages.length > 0) {
|
||||
newSections.push({
|
||||
title: sec.title,
|
||||
pages: pages
|
||||
});
|
||||
}
|
||||
});
|
||||
proj.sections = newSections;
|
||||
|
||||
}
|
||||
|
||||
var groups = {};
|
||||
|
|
|
@ -30,7 +30,7 @@ hexo.extend.tag.register('copy', function(args) {
|
|||
}
|
||||
}
|
||||
|
||||
const copy_id = 'copy-' + ++copy_index + '-' + text.replace(/[^a-z|0-9|.:]/gi, '');
|
||||
const copy_id = 'copy_' + ++copy_index + '-' + text.replace(/[^a-z|0-9|.:]/gi, '');
|
||||
|
||||
var el = '';
|
||||
el += '<div class="tag-plugin copy"';
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var tab_index = 0;
|
||||
|
||||
module.exports = ctx => function(args, content) {
|
||||
var el = '';
|
||||
var arr = content.split(/<!--\s*(.*?)\s*-->/g).filter((item, i) => {
|
||||
|
@ -28,16 +30,14 @@ module.exports = ctx => function(args, content) {
|
|||
}
|
||||
});
|
||||
|
||||
args = ctx.args.map(args, ['active', 'align'], ['tabName']);
|
||||
const tabName = args.tabName;
|
||||
args = ctx.args.map(args, ['active', 'align']);
|
||||
const tabName = 'tab_' + ++tab_index;
|
||||
const tabActive = Number(args.active) || 0;
|
||||
|
||||
let tabId = 0;
|
||||
let tabNav = '';
|
||||
let tabContent = '';
|
||||
|
||||
if (!tabName) ctx.log.warn('Tabs block must have unique name!');
|
||||
|
||||
tabs.forEach((tab, i) => {
|
||||
let caption = tab.header.substring(4);
|
||||
let content = ctx.render.renderSync({ text: tab.body, engine: 'markdown' }).trim();
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
.l_left[layout='wiki'] .widget-wrap#toc
|
||||
margin-top: 0
|
||||
.widget-body
|
||||
margin-top: 0
|
||||
.widget-wrap#toc
|
||||
.widget-body+.widget-header
|
||||
margin-top: 1rem
|
||||
|
||||
|
||||
// 其它分页链接
|
||||
.widget-wrap#toc .doc-tree:not(:only-child)
|
||||
.widget-wrap#toc .multi .doc-tree
|
||||
border-radius: 4px
|
||||
margin: 4px 0
|
||||
background: var(--block)
|
||||
|
@ -33,7 +33,7 @@
|
|||
|
||||
|
||||
// 当前分页链接
|
||||
.widget-wrap#toc .doc-tree.active:not(:only-child)
|
||||
.widget-wrap#toc .multi .doc-tree.active
|
||||
a.doc-tree-link
|
||||
background: var(--block)
|
||||
font-weight: 700
|
||||
|
|
Loading…
Reference in New Issue