[opt] wiki sort
This commit is contained in:
parent
e898a4a818
commit
80e6e749cc
|
@ -24,7 +24,7 @@ function layoutDiv() {
|
||||||
arr = site.posts.filter( p => p.title && p.title.length > 0)
|
arr = site.posts.filter( p => p.title && p.title.length > 0)
|
||||||
}
|
}
|
||||||
el += '<div class="widget-body related-posts fs14">';
|
el += '<div class="widget-body related-posts fs14">';
|
||||||
arr = arr.sort((p1, p2) => { p1.order > p2.order })
|
arr = arr.sort((p1, p2) => p1.order > p2.order ? -1 : 1)
|
||||||
arr.length = item.limit
|
arr.length = item.limit
|
||||||
arr.forEach(post => {
|
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) + '">';
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* doc_tree.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
|
* doc_tree.js v2 | https://github.com/xaoxuu/hexo-theme-stellar/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
@ -33,129 +33,129 @@ module.exports = ctx => {
|
||||||
const wiki_pages = pages.filter(p => (p.layout === 'wiki') && (p.wiki != undefined) && (p.wiki.length > 0)).map(p => new WikiPage(p))
|
const wiki_pages = pages.filter(p => (p.layout === 'wiki') && (p.wiki != undefined) && (p.wiki.length > 0)).map(p => new WikiPage(p))
|
||||||
|
|
||||||
// 数据整合:项目标签
|
// 数据整合:项目标签
|
||||||
var all_tag_name = [];
|
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 (all_tag_name.includes(tags) === false) {
|
if (all_tag_name.includes(tags) === false) {
|
||||||
all_tag_name.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 (all_tag_name.includes(tag) === false) {
|
if (all_tag_name.includes(tag) === false) {
|
||||||
all_tag_name.push(tag);
|
all_tag_name.push(tag)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
wiki.projects[id].tags = tags;
|
wiki.projects[id].tags = tags
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 补充未分组的项目
|
// 补充未分组的项目
|
||||||
const projs = Object.keys(wiki.projects);
|
const projs = Object.keys(wiki.projects)
|
||||||
wiki_pages.forEach((p, i) => {
|
wiki_pages.forEach((p, i) => {
|
||||||
if (projs.includes(p.wiki) == false) {
|
if (projs.includes(p.wiki) == false) {
|
||||||
if (wiki.projects[p.wiki] == undefined) {
|
if (wiki.projects[p.wiki] == undefined) {
|
||||||
wiki.projects[p.wiki] = {};
|
wiki.projects[p.wiki] = {}
|
||||||
wiki.projects[p.wiki].pages = [];
|
wiki.projects[p.wiki].pages = []
|
||||||
}
|
}
|
||||||
var proj = wiki.projects[p.wiki];
|
var proj = wiki.projects[p.wiki]
|
||||||
if (proj.description == undefined) {
|
if (proj.description == undefined) {
|
||||||
proj.description = p.description;
|
proj.description = p.description
|
||||||
}
|
}
|
||||||
wiki.projects[p.wiki].pages.push(p);
|
wiki.projects[p.wiki].pages.push(p)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
// 补充项目名称和首页
|
// 补充项目名称和首页
|
||||||
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.id = id;
|
proj.id = id
|
||||||
if (proj.title == undefined || proj.title.length === 0) {
|
if (proj.title == undefined || proj.title.length === 0) {
|
||||||
proj.title = id;
|
proj.title = id
|
||||||
}
|
}
|
||||||
if (proj.name == undefined || proj.name.length == 0) {
|
if (proj.name == undefined || proj.name.length == 0) {
|
||||||
proj.name = id;
|
proj.name = id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 补充 order
|
// 补充 order
|
||||||
wiki_pages.forEach((p, i) => {
|
wiki_pages.forEach((p, i) => {
|
||||||
if (p.order == undefined) {
|
if (p.order == undefined) {
|
||||||
p.order = 0;
|
p.order = 0
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
// 数据整合:每个项目的子页面
|
// 数据整合:每个项目的子页面
|
||||||
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]
|
||||||
const proj_pages = wiki_pages.filter( p => p.wiki === id ).sort((p1, p2) => { p1.order < p2.order });
|
let proj_pages = wiki_pages.filter(p => p.wiki === id).sort((p1, p2) => p1.order < p2.order ? -1 : 1)
|
||||||
if (!proj_pages || proj_pages.length == 0) {
|
if (!proj_pages || proj_pages.length == 0) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
proj.homepage = proj_pages[0]
|
proj.homepage = proj_pages[0]
|
||||||
// 内页按 section 分组
|
// 内页按 section 分组
|
||||||
var section_configs = [];
|
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) {
|
||||||
section_configs.push({
|
section_configs.push({
|
||||||
title: t,
|
title: t,
|
||||||
from: range[0],
|
from: range[0],
|
||||||
to: range[1]
|
to: range[1]
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var sections = [];
|
var sections = []
|
||||||
section_configs.forEach((sec, i) => {
|
section_configs.forEach((sec, i) => {
|
||||||
const sec_pages = proj_pages.filter( p => p.order >= sec.from && p.order <= sec.to )
|
const sec_pages = proj_pages.filter( p => p.order >= sec.from && p.order <= sec.to )
|
||||||
if (sec_pages && sec_pages.length > 0) {
|
if (sec_pages && sec_pages.length > 0) {
|
||||||
sections.push({
|
sections.push({
|
||||||
title: sec.title,
|
title: sec.title,
|
||||||
pages: sec_pages
|
pages: sec_pages
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
proj.sections = sections
|
proj.sections = sections
|
||||||
proj.pages = proj_pages
|
proj.pages = proj_pages
|
||||||
}
|
}
|
||||||
|
|
||||||
// 全站所有的项目标签
|
// 全站所有的项目标签
|
||||||
var all_tags = {};
|
var all_tags = {}
|
||||||
all_tag_name.forEach((tag_name, 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(tag_name) === true && projs.includes(tag_name) === 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[tag_name] = {
|
all_tags[tag_name] = {
|
||||||
name: tag_name,
|
name: tag_name,
|
||||||
path: (ctx.config.wiki_dir || 'wiki') + '/tags/' + tag_name + '/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((tag_name, i) => {
|
proj.tags.forEach((tag_name, i) => {
|
||||||
let tagObj = all_tags[tag_name];
|
let tagObj = all_tags[tag_name]
|
||||||
related = related.concat(tagObj.items);
|
related = related.concat(tagObj.items)
|
||||||
related = [...new Set(related)];
|
related = [...new Set(related)]
|
||||||
});
|
})
|
||||||
proj.related = related;
|
proj.related = related
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
ctx.theme.config.wiki = wiki
|
||||||
|
|
||||||
};
|
}
|
||||||
|
|
|
@ -14,14 +14,13 @@
|
||||||
|
|
||||||
a.more
|
a.more
|
||||||
padding: 0.25rem 0.5rem
|
padding: 0.25rem 0.5rem
|
||||||
|
|
||||||
border-radius: $border-block
|
border-radius: $border-block
|
||||||
color: var(--text-p1)
|
color: var(--text-p1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.related-posts
|
.related-posts
|
||||||
width: 100%
|
max-width: 100%
|
||||||
margin: 1rem 0
|
margin: 1rem 0
|
||||||
.item
|
.item
|
||||||
line-height: 1.2
|
line-height: 1.2
|
||||||
|
|
|
@ -73,7 +73,6 @@
|
||||||
.widget-wrap#related .widget-body a
|
.widget-wrap#related .widget-body a
|
||||||
margin-top: 0.5rem
|
margin-top: 0.5rem
|
||||||
margin-bottom: 1rem
|
margin-bottom: 1rem
|
||||||
max-width: 'calc(100% - %s * 2)' % var(--gap-l)
|
|
||||||
.title
|
.title
|
||||||
font-weight: 700
|
font-weight: 700
|
||||||
font-size: $fs-14
|
font-size: $fs-14
|
||||||
|
|
Loading…
Reference in New Issue