[opt] wiki performance optimization
This commit is contained in:
parent
79e380b4ee
commit
ff168d322f
|
@ -28,7 +28,7 @@ sidebar:
|
||||||
index: welcome, recent, timeline # for home/wiki/categories/tags/archives/404 pages
|
index: welcome, recent, timeline # for home/wiki/categories/tags/archives/404 pages
|
||||||
page: welcome, toc # for pages using 'layout:page'
|
page: welcome, toc # for pages using 'layout:page'
|
||||||
post: toc, ghrepo, ghissues # for pages using 'layout:post'
|
post: toc, ghrepo, ghissues # for pages using 'layout:post'
|
||||||
wiki: toc, ghrepo, ghissues, related # for pages using 'layout:wiki'
|
wiki: ghrepo, toc, ghissues, related # for pages using 'layout:wiki'
|
||||||
|
|
||||||
######## Index ########
|
######## Index ########
|
||||||
post-index: # 近期发布 分类 标签 归档 and ...
|
post-index: # 近期发布 分类 标签 归档 and ...
|
||||||
|
|
|
@ -13,9 +13,7 @@ function layoutDiv() {
|
||||||
// 项目分类
|
// 项目分类
|
||||||
for (let id of Object.keys(theme.wiki.all_tags)) {
|
for (let id of Object.keys(theme.wiki.all_tags)) {
|
||||||
let tag = theme.wiki.all_tags[id];
|
let tag = theme.wiki.all_tags[id];
|
||||||
let projects = tag.items.filter(function(item){
|
let projects = tag.items.filter(item => item.index !== false)
|
||||||
return item.index !== false;
|
|
||||||
})
|
|
||||||
if (projects && projects.length > 0) {
|
if (projects && projects.length > 0) {
|
||||||
el += '<a';
|
el += '<a';
|
||||||
if (tag.name && tag.name.length > 0 && page.tagName === tag.name) {
|
if (tag.name && tag.name.length > 0 && page.tagName === tag.name) {
|
||||||
|
|
|
@ -13,20 +13,20 @@ function layoutDiv() {
|
||||||
// body
|
// body
|
||||||
var arr = [];
|
var arr = [];
|
||||||
if (page.menu_id == 'wiki') {
|
if (page.menu_id == 'wiki') {
|
||||||
arr = theme.wiki.all_pages.filter(function(p){
|
arr = theme.wiki.all_pages.filter( p => {
|
||||||
if (p.wiki) {
|
if (p.wiki) {
|
||||||
let proj = theme.wiki.projects[p.wiki];
|
let proj = theme.wiki.projects[p.wiki];
|
||||||
return proj.index != false;
|
return proj.index != false;
|
||||||
}
|
}
|
||||||
return false;
|
return false
|
||||||
});
|
})
|
||||||
} else {
|
} else {
|
||||||
arr = site.posts.filter(function(p){
|
arr = site.posts.filter( p => p.title && p.title.length > 0)
|
||||||
return p.title && p.title.length > 0;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
el += '<div class="widget-body related-posts fs14">';
|
el += '<div class="widget-body related-posts fs14">';
|
||||||
arr.sort("updated", -1).limit(item.limit).each(function(post) {
|
arr = arr.sort((p1, p2) => { p1.order > p2.order })
|
||||||
|
arr.length = item.limit
|
||||||
|
arr.forEach(post => {
|
||||||
el += '<a class="item title" href="' + url_for(post.link || post.path) + '">';
|
el += '<a class="item title" href="' + url_for(post.link || post.path) + '">';
|
||||||
el += '<span class="title">'
|
el += '<span class="title">'
|
||||||
if (post.layout == 'wiki') {
|
if (post.layout == 'wiki') {
|
||||||
|
|
|
@ -28,9 +28,7 @@ function layout_posts(partial) {
|
||||||
if (is_home()) {
|
if (is_home()) {
|
||||||
// pinned posts
|
// pinned posts
|
||||||
if (page.current == 1) {
|
if (page.current == 1) {
|
||||||
var pinned = site.posts.filter(function(post){
|
var pinned = site.posts.filter(post => post.pin != undefined).sort((config.index_generator && config.index_generator.order_by) || '-date');
|
||||||
return post.pin != undefined;
|
|
||||||
}).sort((config.index_generator && config.index_generator.order_by) || '-date');
|
|
||||||
pinned.forEach((post, i) => {
|
pinned.forEach((post, i) => {
|
||||||
el += layout_post_card('post', post, partial(post));
|
el += layout_post_card('post', post, partial(post));
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,51 +4,50 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function page(page) {
|
class WikiPage {
|
||||||
return {
|
constructor(page) {
|
||||||
title: page.title,
|
this.id = page._id
|
||||||
path: page.path,
|
this.title = page.title
|
||||||
wiki: page.wiki
|
this.path = page.path
|
||||||
};
|
this.layout = page.layout
|
||||||
}
|
this.seo_title = page.seo_title
|
||||||
|
this.wiki = page.wiki
|
||||||
module.exports = hexo => {
|
this.order = page.order || 0
|
||||||
const data = hexo.locals.get('data');
|
|
||||||
if (hexo.theme.config.wiki == undefined) {
|
|
||||||
hexo.theme.config.wiki = {};
|
|
||||||
}
|
|
||||||
if (hexo.theme.config.wiki.projects == undefined) {
|
|
||||||
hexo.theme.config.wiki.projects = {};
|
|
||||||
}
|
|
||||||
if (data.projects) {
|
|
||||||
for (let id of Object.keys(data.projects)) {
|
|
||||||
hexo.theme.config.wiki.projects[id] = data.projects[id];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createWikiObject(ctx) {
|
||||||
|
const wiki = { projects:{} }
|
||||||
|
const { projects } = ctx.locals.get('data')
|
||||||
|
if (projects) {
|
||||||
|
Object.assign(wiki.projects, projects)
|
||||||
|
}
|
||||||
|
return wiki
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ctx => {
|
||||||
// wiki 配置
|
// wiki 配置
|
||||||
var wiki = hexo.theme.config.wiki;
|
var wiki = createWikiObject(ctx)
|
||||||
|
const pages = ctx.locals.get('pages')
|
||||||
// wiki 所有页面
|
// wiki 所有页面
|
||||||
const wiki_pages = hexo.locals.get('pages').filter(function (p) {
|
const wiki_pages = pages.filter(p => (p.layout === 'wiki') && (p.wiki != undefined) && (p.wiki.length > 0)).map(p => new WikiPage(p))
|
||||||
return (p.layout === 'wiki') && (p.wiki != undefined) && (p.wiki.length > 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 数据整合:项目标签
|
// 数据整合:项目标签
|
||||||
var tagNames = [];
|
var all_tag_name = [];
|
||||||
for (let id of Object.keys(wiki.projects)) {
|
for (let id of Object.keys(wiki.projects)) {
|
||||||
let proj = wiki.projects[id];
|
let proj = wiki.projects[id];
|
||||||
let tags = proj.tags;
|
let tags = proj.tags;
|
||||||
if (tags) {
|
if (tags) {
|
||||||
if ((typeof tags == 'string') && tags.constructor == String) {
|
if ((typeof tags == 'string') && tags.constructor == String) {
|
||||||
if (tagNames.includes(tags) === false) {
|
if (all_tag_name.includes(tags) === false) {
|
||||||
tagNames.push(tags);
|
all_tag_name.push(tags);
|
||||||
}
|
}
|
||||||
// 类型转换
|
// 类型转换
|
||||||
tags = [tags];
|
tags = [tags];
|
||||||
} else if ((typeof tags == 'object') && tags.constructor == Array) {
|
} else if ((typeof tags == 'object') && tags.constructor == Array) {
|
||||||
tags.forEach((tag, i) => {
|
tags.forEach((tag, i) => {
|
||||||
if (tagNames.includes(tag) === false) {
|
if (all_tag_name.includes(tag) === false) {
|
||||||
tagNames.push(tag);
|
all_tag_name.push(tag);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -91,19 +90,18 @@ module.exports = hexo => {
|
||||||
// 数据整合:每个项目的子页面
|
// 数据整合:每个项目的子页面
|
||||||
for (let id of Object.keys(wiki.projects)) {
|
for (let id of Object.keys(wiki.projects)) {
|
||||||
let proj = wiki.projects[id];
|
let proj = wiki.projects[id];
|
||||||
proj.pages = wiki_pages.filter(function (p) {
|
const proj_pages = wiki_pages.filter( p => p.wiki === id ).sort((p1, p2) => { p1.order < p2.order });
|
||||||
return p.wiki === id;
|
if (!proj_pages || proj_pages.length == 0) {
|
||||||
}).sort('order');
|
continue
|
||||||
proj.pages.limit(1).forEach((p, i) => {
|
}
|
||||||
proj.homepage = p;
|
proj.homepage = proj_pages[0]
|
||||||
});
|
|
||||||
// 内页按 section 分组
|
// 内页按 section 分组
|
||||||
var sectionConfigs = [];
|
var section_configs = [];
|
||||||
if (proj.sections) {
|
if (proj.sections) {
|
||||||
for (let t of Object.keys(proj.sections)) {
|
for (let t of Object.keys(proj.sections)) {
|
||||||
let range = proj.sections[t];
|
let range = proj.sections[t];
|
||||||
if (range.length > 1) {
|
if (range.length > 1) {
|
||||||
sectionConfigs.push({
|
section_configs.push({
|
||||||
title: t,
|
title: t,
|
||||||
from: range[0],
|
from: range[0],
|
||||||
to: range[1]
|
to: range[1]
|
||||||
|
@ -112,44 +110,43 @@ module.exports = hexo => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var sections = [];
|
var sections = [];
|
||||||
sectionConfigs.forEach((sec, i) => {
|
section_configs.forEach((sec, i) => {
|
||||||
const pages = proj.pages.filter(function (p) {
|
const sec_pages = proj_pages.filter( p => p.order >= sec.from && p.order <= sec.to )
|
||||||
return p.order >= sec.from && p.order <= sec.to;
|
if (sec_pages && sec_pages.length > 0) {
|
||||||
});
|
|
||||||
if (pages && pages.length > 0) {
|
|
||||||
sections.push({
|
sections.push({
|
||||||
title: sec.title,
|
title: sec.title,
|
||||||
pages: pages
|
pages: sec_pages
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
proj.sections = sections;
|
proj.sections = sections
|
||||||
|
proj.pages = proj_pages
|
||||||
}
|
}
|
||||||
|
|
||||||
// 全站所有的项目标签
|
// 全站所有的项目标签
|
||||||
var all_tags = {};
|
var all_tags = {};
|
||||||
tagNames.forEach((tagName, i) => {
|
all_tag_name.forEach((tag_name, i) => {
|
||||||
var projs = [];
|
var projs = [];
|
||||||
for (let id of Object.keys(wiki.projects)) {
|
for (let id of Object.keys(wiki.projects)) {
|
||||||
let proj = wiki.projects[id];
|
let proj = wiki.projects[id];
|
||||||
if (proj.tags && proj.tags.includes(tagName) === true && projs.includes(tagName) === false) {
|
if (proj.tags && proj.tags.includes(tag_name) === true && projs.includes(tag_name) === false) {
|
||||||
projs.push(proj.id);
|
projs.push(proj.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
all_tags[tagName] = {
|
all_tags[tag_name] = {
|
||||||
name: tagName,
|
name: tag_name,
|
||||||
path: (hexo.config.wiki_dir || 'wiki') + '/tags/' + tagName + '/index.html',
|
path: (ctx.config.wiki_dir || 'wiki') + '/tags/' + tag_name + '/index.html',
|
||||||
items: projs
|
items: projs
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// 整合相似项目
|
// 关联相似项目
|
||||||
for (let id of Object.keys(wiki.projects)) {
|
for (let id of Object.keys(wiki.projects)) {
|
||||||
let proj = wiki.projects[id];
|
let proj = wiki.projects[id];
|
||||||
if (proj.tags) {
|
if (proj.tags) {
|
||||||
var related = [];
|
var related = [];
|
||||||
proj.tags.forEach((tagName, i) => {
|
proj.tags.forEach((tag_name, i) => {
|
||||||
let tagObj = all_tags[tagName];
|
let tagObj = all_tags[tag_name];
|
||||||
related = related.concat(tagObj.items);
|
related = related.concat(tagObj.items);
|
||||||
related = [...new Set(related)];
|
related = [...new Set(related)];
|
||||||
});
|
});
|
||||||
|
@ -159,4 +156,6 @@ module.exports = hexo => {
|
||||||
|
|
||||||
wiki.all_tags = all_tags;
|
wiki.all_tags = all_tags;
|
||||||
wiki.all_pages = wiki_pages;
|
wiki.all_pages = wiki_pages;
|
||||||
|
ctx.theme.config.wiki = wiki;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,9 +29,7 @@ hexo.extend.helper.register('popular_posts_wrapper', function(args){
|
||||||
function listItem(obj){
|
function listItem(obj){
|
||||||
var el = '';
|
var el = '';
|
||||||
el += '<a class="item" href="' + obj.path + '" title="' + obj.title + '">';
|
el += '<a class="item" href="' + obj.path + '" title="' + obj.title + '">';
|
||||||
var p = posts.filter(function(p) {
|
var p = posts.filter(p => root + p.path == obj.path)
|
||||||
return root + p.path == obj.path;
|
|
||||||
});
|
|
||||||
if (p && p.length > 0) {
|
if (p && p.length > 0) {
|
||||||
p = p.data[0];
|
p = p.data[0];
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
* utils v1 | https://github.com/xaoxuu/hexo-theme-stellar/
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
hexo.extend.helper.register('get_page', function(id) {
|
||||||
|
const pages = hexo.locals.get('pages');
|
||||||
|
let page = pages.data.find(element => element._id == id)
|
||||||
|
if (page && page._id == id) {
|
||||||
|
return page
|
||||||
|
} else {
|
||||||
|
const posts = hexo.locals.get('posts');
|
||||||
|
let post = posts.data.find(element => element._id == id)
|
||||||
|
if (post && post._id == id) {
|
||||||
|
return post
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
});
|
|
@ -19,9 +19,7 @@ hexo.extend.tag.register('folders', function(args, content) {
|
||||||
el += ' ' + hexo.args.joinTags(args, ['color']).join(' ');
|
el += ' ' + hexo.args.joinTags(args, ['color']).join(' ');
|
||||||
el += '>';
|
el += '>';
|
||||||
|
|
||||||
var arr = content.split(/<!--\s*(.*?)\s*-->/g).filter((item, i) => {
|
var arr = content.split(/<!--\s*(.*?)\s*-->/g).filter(item => item.trim().length > 0)
|
||||||
return item.trim().length > 0;
|
|
||||||
});
|
|
||||||
if (arr.length > 0) {
|
if (arr.length > 0) {
|
||||||
var nodes = [];
|
var nodes = [];
|
||||||
arr.forEach((item, i) => {
|
arr.forEach((item, i) => {
|
||||||
|
|
|
@ -8,9 +8,7 @@ var tab_index = 0;
|
||||||
|
|
||||||
module.exports = ctx => function(args, content) {
|
module.exports = ctx => function(args, content) {
|
||||||
var el = '';
|
var el = '';
|
||||||
var arr = content.split(/<!--\s*(.*?)\s*-->/g).filter((item, i) => {
|
var arr = content.split(/<!--\s*(.*?)\s*-->/g).filter(item => item.trim().length > 0)
|
||||||
return item.trim().length > 0;
|
|
||||||
});
|
|
||||||
if (arr.length < 1) {
|
if (arr.length < 1) {
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,7 @@ hexo.extend.tag.register('split', function(args, content) {
|
||||||
el += ' ' + hexo.args.joinTags(args, ['bg']).join(' ');
|
el += ' ' + hexo.args.joinTags(args, ['bg']).join(' ');
|
||||||
el += '>';
|
el += '>';
|
||||||
|
|
||||||
var arr = content.split(/<!--\s*(.*?)\s*-->/g).filter((item, i) => {
|
var arr = content.split(/<!--\s*(.*?)\s*-->/g).filter(item => item.trim().length > 0)
|
||||||
return item.trim().length > 0;
|
|
||||||
});
|
|
||||||
if (arr.length > 0) {
|
if (arr.length > 0) {
|
||||||
var nodes = [];
|
var nodes = [];
|
||||||
arr.forEach((item, i) => {
|
arr.forEach((item, i) => {
|
||||||
|
|
|
@ -49,9 +49,7 @@ function postTimeline(args, content) {
|
||||||
el += '<div class="tag-plugin timeline">';
|
el += '<div class="tag-plugin timeline">';
|
||||||
}
|
}
|
||||||
|
|
||||||
var arr = content.split(/<!--\s*(.*?)\s*-->/g).filter((item, i) => {
|
var arr = content.split(/<!--\s*(.*?)\s*-->/g).filter(item => item.trim().length > 0)
|
||||||
return item.trim().length > 0;
|
|
||||||
});
|
|
||||||
if (arr.length > 0) {
|
if (arr.length > 0) {
|
||||||
var nodes = [];
|
var nodes = [];
|
||||||
arr.forEach((item, i) => {
|
arr.forEach((item, i) => {
|
||||||
|
|
|
@ -50,7 +50,7 @@ article.md.content
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.md
|
article.md
|
||||||
ul:not(:last-child),
|
ul:not(:last-child),
|
||||||
ol:not(:last-child)
|
ol:not(:last-child)
|
||||||
padding-bottom: .5rem
|
padding-bottom: .5rem
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
.widget-wrap#toc
|
.widget-wrap#toc
|
||||||
.widget-body+.widget-header
|
.widget-header
|
||||||
margin-top: 1rem
|
margin-top: 1rem
|
||||||
|
|
||||||
.widget-wrap.multi#toc .widget-header
|
.widget-wrap.multi#toc .widget-header
|
||||||
|
|
|
@ -9,8 +9,9 @@
|
||||||
z-index: 1
|
z-index: 1
|
||||||
line-height: 1.2
|
line-height: 1.2
|
||||||
.widget-wrap
|
.widget-wrap
|
||||||
margin: 1rem var(--gap-l) 3rem var(--gap-l)
|
margin: 1rem var(--gap-l) 2rem var(--gap-l)
|
||||||
.widget-header
|
.widget-header
|
||||||
|
margin-top: 3rem
|
||||||
display: flex
|
display: flex
|
||||||
justify-content: space-between
|
justify-content: space-between
|
||||||
align-items: center
|
align-items: center
|
||||||
|
@ -50,7 +51,6 @@
|
||||||
margin-top: 0
|
margin-top: 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.l_left .widgets
|
.l_left .widgets
|
||||||
.widget-wrap#recent .widget-body
|
.widget-wrap#recent .widget-body
|
||||||
display: flex
|
display: flex
|
||||||
|
|
|
@ -82,31 +82,31 @@ set_text_black()
|
||||||
set_darkmode_tags()
|
set_darkmode_tags()
|
||||||
.tag-plugin[color='red']
|
.tag-plugin[color='red']
|
||||||
--theme-border: mix($c-red, black, 70)
|
--theme-border: mix($c-red, black, 70)
|
||||||
--theme-bg: mix($c-red, black, 20)
|
--theme-bg: mix($c-red, black, 35)
|
||||||
|
|
||||||
.tag-plugin[color='orange']
|
.tag-plugin[color='orange']
|
||||||
--theme-border: mix($c-orange, black, 70)
|
--theme-border: mix($c-orange, black, 70)
|
||||||
--theme-bg: mix($c-orange, black, 20)
|
--theme-bg: mix($c-orange, black, 35)
|
||||||
|
|
||||||
.tag-plugin[color='yellow']
|
.tag-plugin[color='yellow']
|
||||||
--theme-border: mix($c-yellow, black, 70)
|
--theme-border: mix($c-yellow, black, 70)
|
||||||
--theme-bg: mix($c-yellow, black, 20)
|
--theme-bg: mix($c-yellow, black, 30)
|
||||||
|
|
||||||
.tag-plugin[color='green']
|
.tag-plugin[color='green']
|
||||||
--theme-border: mix($c-green, black, 70)
|
--theme-border: mix($c-green, black, 70)
|
||||||
--theme-bg: mix($c-green, black, 20)
|
--theme-bg: mix($c-green, black, 30)
|
||||||
|
|
||||||
.tag-plugin[color='cyan']
|
.tag-plugin[color='cyan']
|
||||||
--theme-border: mix($c-cyan, black, 70)
|
--theme-border: mix($c-cyan, black, 70)
|
||||||
--theme-bg: mix($c-cyan, black, 20)
|
--theme-bg: mix($c-cyan, black, 30)
|
||||||
|
|
||||||
.tag-plugin[color='blue']
|
.tag-plugin[color='blue']
|
||||||
--theme-border: mix($c-blue, black, 70)
|
--theme-border: mix($c-blue, black, 70)
|
||||||
--theme-bg: mix($c-blue, black, 20)
|
--theme-bg: mix($c-blue, black, 35)
|
||||||
|
|
||||||
.tag-plugin[color='purple']
|
.tag-plugin[color='purple']
|
||||||
--theme-border: mix($c-purple, black, 70)
|
--theme-border: mix($c-purple, black, 70)
|
||||||
--theme-bg: mix($c-purple, black, 20)
|
--theme-bg: mix($c-purple, black, 40)
|
||||||
|
|
||||||
.tag-plugin[color='light']
|
.tag-plugin[color='light']
|
||||||
--theme-border: white
|
--theme-border: white
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
grid-template-columns: repeat(auto-fill, "calc((100% - 1 * %s) / 2)" % 16px)
|
grid-template-columns: repeat(auto-fill, "calc((100% - 1 * %s) / 2)" % 16px)
|
||||||
>.cell
|
>.cell
|
||||||
margin: 1rem 0
|
margin: 1rem 0
|
||||||
|
p:first-child>strong:only-child
|
||||||
|
font-size: $fs-h4
|
||||||
>.cell>
|
>.cell>
|
||||||
p
|
p
|
||||||
line-height: 1.5
|
line-height: 1.5
|
||||||
|
@ -30,3 +32,7 @@
|
||||||
&[bg='card']>.cell
|
&[bg='card']>.cell
|
||||||
background: var(--card)
|
background: var(--card)
|
||||||
box-shadow: $boxshadow-card
|
box-shadow: $boxshadow-card
|
||||||
|
trans2 box-shadow transform
|
||||||
|
&:hover
|
||||||
|
transform: translateY(-1px)
|
||||||
|
box-shadow: $boxshadow-card-float
|
Loading…
Reference in New Issue