[opt] toc -> tree

This commit is contained in:
xaoxuu 2024-02-12 23:12:29 +08:00
parent 23aab88e04
commit c34c56a462
1 changed files with 8 additions and 8 deletions

View File

@ -30,8 +30,8 @@ function getWikiObject(ctx) {
if ((typeof obj.tags == 'string') && obj.tags.constructor == String) { if ((typeof obj.tags == 'string') && obj.tags.constructor == String) {
obj.tags = [obj.tags] obj.tags = [obj.tags]
} }
if ((typeof obj.toc == 'object') && obj.toc.constructor == Array) { if ((typeof obj.tree == 'object') && obj.tree.constructor == Array) {
obj.toc = { '': obj.toc } obj.tree = { '': obj.tree }
} }
obj.id = newKey obj.id = newKey
if (obj.sort == null) { if (obj.sort == null) {
@ -108,9 +108,9 @@ module.exports = ctx => {
// 首页 // 首页
// 未特别指定首页时获取TOC第一页作为首页 // 未特别指定首页时获取TOC第一页作为首页
var homepage = item.homepage var homepage = item.homepage
if (homepage == null && item.toc != null) { if (homepage == null && item.tree != null) {
for (let id of Object.keys(item.toc)) { for (let id of Object.keys(item.tree)) {
const sec = item.toc[id] const sec = item.tree[id]
for (let key of sec) { for (let key of sec) {
let hs = sub_pages.filter(p => p.path_key == item.base_dir + key) let hs = sub_pages.filter(p => p.path_key == item.base_dir + key)
if (hs.length > 0) { if (hs.length > 0) {
@ -134,11 +134,11 @@ module.exports = ctx => {
// 内页分组 // 内页分组
var sections = [] var sections = []
var others = sub_pages var others = sub_pages
if (item.toc) { if (item.tree) {
// 根据配置设置顺序 // 根据配置设置顺序
for (let title of Object.keys(item.toc)) { for (let title of Object.keys(item.tree)) {
var sec = { title: title, pages: []} var sec = { title: title, pages: []}
for (let key of item.toc[title]) { for (let key of item.tree[title]) {
sec.pages = sec.pages.concat(sub_pages.filter(p => p.path_key == item.base_dir + key)) sec.pages = sec.pages.concat(sub_pages.filter(p => p.path_key == item.base_dir + key))
others = others.filter(p => p.path_key != item.base_dir + key) others = others.filter(p => p.path_key != item.base_dir + key)
} }