From 8c22e1f22f5a67a9921957ccf6fefb46dde2ed99 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Sat, 20 Jan 2024 01:57:55 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20project=E2=80=99s=20homepage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/events/lib/doc_tree.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/events/lib/doc_tree.js b/scripts/events/lib/doc_tree.js index 153b322..4f733e4 100644 --- a/scripts/events/lib/doc_tree.js +++ b/scripts/events/lib/doc_tree.js @@ -104,25 +104,30 @@ module.exports = ctx => { // 首页 // 未特别指定首页时,获取TOC第一页作为首页 - if (item.homepage == null && item.toc != null) { + var homepage = item.homepage + if (homepage == null && item.toc != null) { for (let id of Object.keys(item.toc)) { const sec = item.toc[id] for (let key of sec) { let hs = sub_pages.filter(p => p.path_key == item.base_dir + key) if (hs.length > 0) { - item.homepage = hs[0] + homepage = hs[0] break } } - if (item.homepage != null) { + if (homepage != null) { break } } } - if (item.homepage == null) { - item.homepage = sub_pages[0] + if (homepage == null) { + homepage = sub_pages[0] } - item.homepage.is_homepage = true + if (typeof homepage == 'string') { + homepage = {path: homepage} + } + homepage.is_homepage = true + item.homepage = homepage // 内页分组 var sections = [] var others = sub_pages