';
- if (page.logo.large) {
- el += '';
+ if (proj.logo.large) {
+ el += '';
} else {
- el += '';
+ el += '';
}
el += '
';
}
- if (page.title && cover.includes('title')) {
+ if ((proj.title || page.title) && cover.includes('title')) {
el += '';
- el += '' + (page.wiki || page.title) + '';
+ el += '' + (proj.title || page.title) + '';
el += '
';
}
- if (page.description && cover.includes('description')) {
- el += '' + page.description + '
';
+ if ((proj.description || page.description) && cover.includes('description')) {
+ el += '' + (proj.description || page.description) + '
';
}
el += '';
el += '' + __('btn.getting_started') + '';
diff --git a/layout/_partial/main/navbar/breadcrumb.ejs b/layout/_partial/main/navbar/breadcrumb.ejs
index c9a15a6..4daaa9f 100644
--- a/layout/_partial/main/navbar/breadcrumb.ejs
+++ b/layout/_partial/main/navbar/breadcrumb.ejs
@@ -1,66 +1,87 @@
-<% if (page.breadcrumb != false) { %>
-
- <% if (page.layout == 'post') { %>
- <%
- var firstCat = '';
+<%
+function layoutDiv() {
+ var el = '';
+ if (page.breadcrumb === false) {
+ return el;
+ }
+ el += '
';
+ return el;
+}
+%>
+<%- layoutDiv() %>
diff --git a/layout/_partial/main/navbar/list_wiki.ejs b/layout/_partial/main/navbar/list_wiki.ejs
index 95aba36..4400ee4 100644
--- a/layout/_partial/main/navbar/list_wiki.ejs
+++ b/layout/_partial/main/navbar/list_wiki.ejs
@@ -1,28 +1,34 @@
- ';
+ return el;
+}
+%>
+
+<%- layoutDiv() %>
diff --git a/layout/_partial/main/post_list/wiki_card.ejs b/layout/_partial/main/post_list/wiki_card.ejs
index 3f2e308..1bea177 100644
--- a/layout/_partial/main/post_list/wiki_card.ejs
+++ b/layout/_partial/main/post_list/wiki_card.ejs
@@ -1,29 +1,23 @@
<%
function layoutDiv() {
var el = '';
- if (post.logo && post.logo.src) {
+ if (proj.logo && proj.logo.src) {
el += '';
+ if (page.layout === "post") {
+ var firstCat = "";
if (page.categories && page.categories.length > 0) {
firstCat = page.categories.data[0].name;
}
- %>
-
-<% } %>
+ el += '
- ';
+ // 发布日期
+ el += '
- <%- __('meta.created') %>
-
- <% } else if (page.layout == 'wiki') { %>
- <%
- var catPage = '';
- site.pages.filter(function (p) {
- return p.layout == 'index' && p.title && p.wiki && p.wiki.includes(page.wiki)
- }).limit(1).each(function(p) {
- catPage = p;
- });
- %>
-
-
- <%- __('meta.updated') %>
-
- <% } else { %>
-
- <% } %>
- ';
+ el += __("meta.created") + ' ';
+ el += '
';
+ } else if (page.layout === "wiki" && page.wiki && page.wiki.length > 0) {
+ var cat_name = '';
+ let proj = theme.wiki.projects[page.wiki];
+ if (proj.group && proj.group.length > 0) {
+ let group = theme.wiki.groups[proj.group];
+ if (group) {
+ cat_name = group.title;
+ }
+ }
+ el += ' ';
+ // 更新日期
+ el += '';
+ el += __("meta.updated") + ' ';
+ el += '
';
+ } else {
+ el += ' ';
+ }
+ el += '';
- el += '';
el += '
';
}
el += '';
- var cat = '';
- site.pages.filter(function (p) {
- return p.layout == 'index' && p.title && p.wiki && p.wiki.includes(post.wiki)
- }).limit(1).each(function(p) {
- cat = p.title;
- });
- if (cat) {
- el += ''
+ for (let id of Object.keys(theme.sidebar.menu)) {
+ let item = theme.sidebar.menu[id];
+ if (item == undefined || item.length == 0) {
+ continue;
+ }
+ el += '';
+ el += __(md_text(item));
+ el += '';
+ }
+ el += ' ';
+ return el;
+}
function layoutMainMenu() {
var el = '';
el += partial('logo');
@@ -31,14 +50,17 @@ function layoutDiv() {
el += ' mobile-only';
}
el += '">';
- if (page.layout === 'wiki') {
- el += layoutWikiMenu();
+ el += partial('logo');
+ if (page.layout === 'wiki' && page.wiki) {
+ if (page.menu_id !== 'wiki') {
+ el += layoutMenu();
+ }
} else {
- el += layoutMainMenu();
+ el += layoutMenu();
}
el += '';
return el;
}
%>
-<%- layoutDiv() %>
\ No newline at end of file
+<%- layoutDiv() %>
diff --git a/layout/_partial/sidebar/logo.ejs b/layout/_partial/sidebar/logo.ejs
index cace7b4..9c288ca 100644
--- a/layout/_partial/sidebar/logo.ejs
+++ b/layout/_partial/sidebar/logo.ejs
@@ -1,16 +1,12 @@
<%
-var wiki;
-if (page.layout === 'wiki') {
- site.pages.filter(function (p) {
- return p.layout == 'wiki' && p.wiki == page.wiki && p.description
- }).limit(1).each(function(p) {
- wiki = p;
- });
+var proj;
+if (page.layout === 'wiki' && page.wiki) {
+ proj = theme.wiki.projects[page.wiki];
}
function layoutDiv() {
var el = '';
- if (page.layout === 'wiki') {
+ if (page.layout === 'wiki' && proj.index !== false) {
el += '
';
return el;
}
diff --git a/layout/_partial/sidebar/header.ejs b/layout/_partial/sidebar/header.ejs
index bd38f17..441ceef 100644
--- a/layout/_partial/sidebar/header.ejs
+++ b/layout/_partial/sidebar/header.ejs
@@ -1,4 +1,23 @@
<%
+function layoutMenu() {
+ var el = '';
+ el += '';
// all products
el += '';
@@ -18,16 +14,18 @@ function layoutDiv() {
el += __('btn.all_wiki');
el += '';
// this product
- if (wiki === undefined) {
+ if (proj === undefined) {
+ // 如果没有项目名,则使用menu中显示的名字
if (page.menu_id && theme.sidebar.menu[page.menu_id] && md_link(theme.sidebar.menu[page.menu_id])) {
- wiki = new Object();
- wiki.path = md_link(theme.sidebar.menu[page.menu_id]);
- wiki.wiki = __(md_text(theme.sidebar.menu[page.menu_id]));
+ proj = {
+ path: md_link(theme.sidebar.menu[page.menu_id]),
+ wiki: __(md_text(theme.sidebar.menu[page.menu_id]))
+ };
}
}
- if (wiki !== undefined) {
- el += '';
- el += wiki.wiki;
+ if (proj !== undefined) {
+ el += '';
+ el += proj.title || proj.wiki;
el += '';
}
} else {
diff --git a/layout/_partial/sidebar/widgets/wiki_more.ejs b/layout/_partial/sidebar/widgets/wiki_more.ejs
index b546bb8..b17d4ff 100644
--- a/layout/_partial/sidebar/widgets/wiki_more.ejs
+++ b/layout/_partial/sidebar/widgets/wiki_more.ejs
@@ -3,38 +3,36 @@ function layoutDiv() {
if (page.layout !== "wiki") {
return '';
}
- var current_group;
- site.pages.filter(function (p) {
- return p.layout == "index" && p.title && p.wiki && p.wiki.includes(page.wiki)
- }).limit(1).each(function(p) {
- current_group = p;
- });
- if (current_group === undefined || current_group.wiki.length < 1) {
- return '';
- }
var el = '';
- el += ' ';
+ let proj = theme.wiki.projects[page.wiki];
+ if (proj.group && proj.group.length > 0) {
+ let group = theme.wiki.groups[proj.group];
+ let projects = group.projects.filter(function(proj){
+ return proj.index !== false;
+ })
+ if (projects && projects.length > 1) {
+ var el = '';
+ el += ' ';
+ }
+ }
return el;
}
%>
diff --git a/layout/index.ejs b/layout/index.ejs
index 6ee6f2b..1baf4f9 100755
--- a/layout/index.ejs
+++ b/layout/index.ejs
@@ -1,6 +1,6 @@
<%
-if (page.menu_id == undefined) {
- if (page.layout == 'index' && page.title && page.wiki) {
+if (page.menu_id === undefined) {
+ if (page.layout === 'index' && page.wiki) {
page.menu_id = 'wiki';
} else {
page.menu_id = 'post';
@@ -10,12 +10,9 @@ if (page.title && page.wiki) {
page.robots = 'noindex,follow';
}
-function layout_post_card(type, post, content) {
+function layout_post_card(layout, post, content) {
var el = '';
- if (post.post == undefined) {
- post.post = 'article';
- }
- el += '';
+ el += '';
el += '';
el += content;
el += ' ';
@@ -37,7 +34,7 @@ function layout_posts(partial) {
}
// unpinned posts
page.posts.each(function(post){
- if (post.pin == undefined) {
+ if (post.pin === undefined) {
el += layout_post_card('post', post, partial(post));
}
})
@@ -53,51 +50,41 @@ function layout_posts(partial) {
function layout_wikis(partial) {
var el = '';
var wikis = [];
- if (page.title && page.wiki) {
- // filtered wikis
- page.wiki.forEach((wiki, i) => {
- site.pages.filter(function (p) {
- return p.layout == 'wiki' && p.wiki == wiki && p.description;
- }).limit(1).each(function(post) {
- wikis.push(post);
+ const projects = theme.wiki.projects;
+ for (let proj_name of Object.keys(projects)) {
+ let proj = projects[proj_name];
+ if (proj.index === false || proj.pages === undefined || proj.pages.length === 0) {
+ continue;
+ }
+ if (page.filter === false) {
+ // all wikis
+ proj.pages.sort('order').limit(1).forEach((p0, i) => {
+ el += '
';
+ el += layout_post_card('wiki', p0, partial(proj));
+ el += '
';
});
- });
- el += '';
- wikis.forEach(function(wiki) {
- el += layout_post_card('wiki', wiki, partial(wiki));
- });
- el += '
';
- } else {
- // all wikis
- wikis = site.pages.filter(function (p) {
- if (p.layout == 'wiki' && p.wiki && p.description) {
- if (p.order == undefined) {
- p.order = 0;
- }
- return true;
- } else {
- return false;
- }
- }).sort('order');
- el += '';
- wikis.forEach(function(wiki) {
- el += layout_post_card('wiki', wiki, partial(wiki));
- });
- el += '
';
+ } else if (page.group === proj.group) {
+ // filtered wikis
+ proj.pages.sort('order').limit(1).forEach((p0, i) => {
+ el += '';
+ el += layout_post_card('wiki', p0, partial(proj));
+ el += '
';
+ });
+ }
}
return el;
}
%>
-<% if (page.menu_id == 'post') { %>
+<% if (page.menu_id === 'post') { %>
<%- partial('_partial/main/navbar/list_post') %>
<%- layout_posts(function(post){
return partial('_partial/main/post_list/post_card', {post: post})
}) %>
<%- partial('_partial/main/post_list/paginator') %>
-<% } else if (page.menu_id == 'wiki') { %>
+<% } else if (page.menu_id === 'wiki') { %>
<%- partial('_partial/main/navbar/list_wiki') %>
- <%- layout_wikis(function(post){
- return partial('_partial/main/post_list/wiki_card', {post: post})
+ <%- layout_wikis(function(proj){
+ return partial('_partial/main/post_list/wiki_card', {proj: proj})
}) %>
<% } %>
diff --git a/layout/wiki.ejs b/layout/wiki.ejs
index 1faa23f..672b557 100755
--- a/layout/wiki.ejs
+++ b/layout/wiki.ejs
@@ -1,12 +1,16 @@
<%
-if (page.menu_id == undefined) {
+if (page.menu_id === undefined) {
page.menu_id = 'wiki';
}
-if (page.layout == undefined) {
+if (page.layout === undefined) {
page.layout = 'index';
}
-if (page.title == undefined) {
- page.title = __('btn.wiki');
+if (page.title === undefined) {
+ if (page.group) {
+ page.title = page.group;
+ } else {
+ page.title = __('btn.wiki');
+ }
}
function layoutTitle() {
const title = page.h1 || page.title;
@@ -17,11 +21,11 @@ function layoutTitle() {
}
}
%>
-<% if (page.layout == 'index') { %>
+<% if (page.layout === 'index') { %>
<%- partial('index') %>
<% } else { %>
<%
- if (page.header == undefined) {
+ if (page.header === undefined) {
page.header = false;
}
%>
diff --git a/scripts/events/index.js b/scripts/events/index.js
index 8a49106..d2fa595 100644
--- a/scripts/events/index.js
+++ b/scripts/events/index.js
@@ -5,6 +5,7 @@
hexo.on('generateBefore', () => {
// Merge config.
require('./lib/config')(hexo);
+ require('./lib/doc_tree')(hexo);
require('./lib/utils')(hexo);
});
diff --git a/scripts/events/lib/doc_tree.js b/scripts/events/lib/doc_tree.js
new file mode 100644
index 0000000..990902c
--- /dev/null
+++ b/scripts/events/lib/doc_tree.js
@@ -0,0 +1,88 @@
+/**
+ * doc_tree.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
+ */
+
+'use strict';
+
+module.exports = hexo => {
+ const data = hexo.locals.get('data');
+ if (data.projects) {
+ if (hexo.theme.config.wiki === undefined) {
+ hexo.theme.config.wiki = {};
+ }
+ if (hexo.theme.config.wiki.projects === undefined) {
+ hexo.theme.config.wiki.projects = {};
+ }
+ for (let id of Object.keys(data.projects)) {
+ hexo.theme.config.wiki.projects[id] = data.projects[id];
+ }
+ }
+ // wiki 配置
+ const { wiki } = hexo.theme.config;
+ // wiki 所有页面
+ const wiki_pages = hexo.locals.get('pages').filter(function (p) {
+ return (p.layout === 'wiki') && (p.wiki !== undefined) && (p.wiki.length > 0);
+ });
+
+ // 数据整合:项目组
+ var cats = [];
+ for (let proj_name of Object.keys(wiki.projects)) {
+ let proj = wiki.projects[proj_name];
+ if (proj.group !== undefined) {
+ if (cats.includes(proj.group) === false) {
+ cats.push(proj.group);
+ }
+ }
+ }
+ // 补充未分组的项目
+ const projs = Object.keys(wiki.projects);
+ wiki_pages.forEach((p, i) => {
+ if (projs.includes(p.wiki) === false) {
+ if (wiki.projects[p.wiki] === undefined) {
+ wiki.projects[p.wiki] = {};
+ wiki.projects[p.wiki].pages = [];
+ }
+ var proj = wiki.projects[p.wiki];
+ if (proj.description === undefined) {
+ proj.description = p.description;
+ }
+ wiki.projects[p.wiki].pages.push(p);
+ }
+ });
+ // 补充项目名称
+ for (let proj_name of Object.keys(wiki.projects)) {
+ let proj = wiki.projects[proj_name];
+ if (proj.title === undefined || proj.title.length === 0) {
+ proj.title = proj_name;
+ }
+ }
+
+ // 数据整合:每个项目的子页面
+ for (let proj_name of Object.keys(wiki.projects)) {
+ let proj = wiki.projects[proj_name];
+ proj.pages = wiki_pages.filter(function (p) {
+ return p.wiki === proj_name;
+ }).sort('order');
+ proj.pages.limit(1).forEach((p, i) => {
+ proj.path = p.path;
+ });
+ }
+
+ var groups = {};
+ cats.forEach((group_name, i) => {
+ var projs = [];
+ for (let proj_name of Object.keys(wiki.projects)) {
+ let proj = wiki.projects[proj_name];
+ if (proj.group === group_name && projs.includes(group_name) === false) {
+ projs.push(proj);
+ }
+ }
+ groups[group_name] = {
+ title: group_name,
+ path: (hexo.config.wiki_dir || 'wiki') + '/categories/' + group_name + '/index.html',
+ projects: projs
+ };
+ });
+ wiki.groups = groups;
+ wiki.all_pages = wiki_pages;
+};
diff --git a/scripts/generators/wiki.js b/scripts/generators/wiki.js
index a93036b..247c0df 100644
--- a/scripts/generators/wiki.js
+++ b/scripts/generators/wiki.js
@@ -10,11 +10,27 @@ hexo.extend.generator.register('wiki', function (locals) {
}
});
if (hasWiki) {
- return {
+ var ret = [];
+ ret.push({
path: (hexo.config.wiki_dir || 'wiki') + '/index.html',
- data: locals.posts,
+ data: {'filter': false},
layout: ['wiki']
+ });
+ if (hexo.theme.config.wiki && hexo.theme.config.wiki.groups) {
+ for (let group_name of Object.keys(hexo.theme.config.wiki.groups)) {
+ let group = hexo.theme.config.wiki.groups[group_name];
+ ret.push({
+ path: group.path,
+ data: {
+ 'filter': true,
+ 'title': group.title,
+ 'group': group.title
+ },
+ layout: ['wiki']
+ });
+ }
}
+ return ret;
} else {
return {};
}
diff --git a/source/css/_layout/sidebar/sidebar.styl b/source/css/_layout/sidebar/sidebar.styl
index 91ff9fd..040556c 100644
--- a/source/css/_layout/sidebar/sidebar.styl
+++ b/source/css/_layout/sidebar/sidebar.styl
@@ -108,7 +108,7 @@ nav.menu
&.active, &:hover
color: var(--text-p1)
background: var(--card)
- box-shadow: 0 0 4px 0px rgba(0, 0, 0, 0.1)
+ box-shadow: 0 0 2px 0px rgba(0, 0, 0, 0.04), 0 0 8px 0px rgba(0, 0, 0, 0.04)
.l_left .menu a.nav-item
flex-grow: 1
diff --git a/source/css/_layout/sidebar/toc_wiki.styl b/source/css/_layout/sidebar/toc_wiki.styl
index 8263b7a..83922f6 100644
--- a/source/css/_layout/sidebar/toc_wiki.styl
+++ b/source/css/_layout/sidebar/toc_wiki.styl
@@ -22,6 +22,8 @@
right: .5rem
&.active
color: var(--text-p1)
+ &:only-child
+ background: var(--card)
&:hover
background: var(--block-hover)
&:after