diff --git a/build/wiki.js b/build/wiki.js index 9154128e..52e739da 100644 --- a/build/wiki.js +++ b/build/wiki.js @@ -2,25 +2,30 @@ const fs = require('fs'); const { root } = require('./utils'); module.exports = () => { - const pages = fs.readdirSync(root('wiki')); - const res = {}; - for (const page of pages) { - const c = fs.readFileSync(root(`wiki/${page}`)).toString().split('\n'); - const pagename = page.split('.')[0]; - res[pagename] = []; - let content = null; - for (let i = 0; i < c.length; i++) { - const line = c[i]; - if (line.startsWith('# ')) { - if (content) res[pagename].push(content); - content = {}; - const t = line.split('# ')[1].split('|'); - [content.title, content.id] = t.map((q) => q.trim()); - content.content = ''; - } else { - content.content = `${content.content}${line}\n`; + const categories = fs.readdirSync(root('wiki')); + const r = {}; + for (const category of categories) { + const pages = fs.readdirSync(root(`wiki/${category}`)); + const res = {}; + for (const page of pages) { + const c = fs.readFileSync(root(`wiki/${category}/${page}`)).toString().split('\n'); + const pagename = page.split('.')[0]; + res[pagename] = []; + let content = null; + for (let i = 0; i < c.length; i++) { + const line = c[i]; + if (line.startsWith('# ')) { + if (content) res[pagename].push(content); + content = {}; + const t = line.split('# ')[1].split('|'); + [content.title, content.id] = t.map((q) => q.trim()); + content.content = ''; + } else { + content.content = `${content.content}${line}\n`; + } } } + r[category] = res; } - return res; + return r; }; diff --git a/hydro/handler/wiki.js b/hydro/handler/wiki.js index 084b4810..9c8fd133 100644 --- a/hydro/handler/wiki.js +++ b/hydro/handler/wiki.js @@ -2,16 +2,17 @@ const { Route, Handler } = require('../service/server'); const { NotFoundError } = require('../error'); class WikiHandler extends Handler { - async get({ page }) { - if (!global.Hydro.wiki[page]) throw new NotFoundError(page); - const contents = global.Hydro.wiki[page]; + async get({ category = 'wiki', page }) { + if (!global.Hydro.wiki[category]) throw new NotFoundError(category); + if (!global.Hydro.wiki[category][page]) throw new NotFoundError(category, page); + const contents = global.Hydro.wiki[category][page]; const path = [ ['Hydro', 'homepage'], - ['wiki', null], - [`wiki_${page}`, null], + [`wiki_${category}`, null], + [`wiki_${category}_${page}`, null], ]; this.response.body = { - path, contents, page_name: `wiki_${page}`, + path, contents, page_name: `wiki_${category}_${page}`, }; this.response.template = 'wiki.html'; } @@ -19,6 +20,7 @@ class WikiHandler extends Handler { async function apply() { Route('wiki', '/wiki/:page', WikiHandler); + Route('wiki_with_category', '/wiki/:category/:page', WikiHandler); } global.Hydro.handler.wiki = module.exports = apply; diff --git a/wiki/deploy.md b/wiki/admin/deploy.md similarity index 100% rename from wiki/deploy.md rename to wiki/admin/deploy.md diff --git a/wiki/admin/judge.md b/wiki/admin/judge.md new file mode 100644 index 00000000..1323658a --- /dev/null +++ b/wiki/admin/judge.md @@ -0,0 +1,7 @@ +# Judge + +评测机配置: + +可直接安装 Judger 模块。相关配置可在系统设置中修改。 + +或者参照 [HydroJudger](https://github.com/hydro-dev/HydroJudger) 部署。 diff --git a/wiki/admin/oauth.md b/wiki/admin/oauth.md new file mode 100644 index 00000000..0865382a --- /dev/null +++ b/wiki/admin/oauth.md @@ -0,0 +1,4 @@ +# OAuth + +Hydro 支持使用 Github 和 Google 登录。申请相应 API Key 填入系统设置。 +p.s. 由于众所周知的原因,需要设置 proxy 设置项。 diff --git a/wiki/development.md b/wiki/development/development.md similarity index 100% rename from wiki/development.md rename to wiki/development/development.md diff --git a/wiki/about.md b/wiki/wiki/about.md similarity index 100% rename from wiki/about.md rename to wiki/wiki/about.md diff --git a/wiki/help.md b/wiki/wiki/help.md similarity index 100% rename from wiki/help.md rename to wiki/wiki/help.md