mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
wiki
This commit is contained in:
1 parent
8c20c34d8b
commit
ca11d80776
45 files changed
+418
-444
No files matched your search
@@ -0,0 +1,27 @@
|
||||
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`;
|
||||
}
|
||||
res[pagename].push(content);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
};
|
||||
Reference in new issue
Block a user