19 lines
918 B
JavaScript
19 lines
918 B
JavaScript
|
|
/* 从生成的页面统计每个模块的章节/小节/千字,用于 README 表格 */
|
||
|
|
const fs = require("fs"), path = require("path");
|
||
|
|
const MOD = "knowledge/sre-learning-path/modules";
|
||
|
|
const dirs = fs.readdirSync(MOD).filter(d => /^s[45]-/.test(d)).sort();
|
||
|
|
let tCh = 0, tSec = 0, tChr = 0;
|
||
|
|
for (const d of dirs) {
|
||
|
|
const files = fs.readdirSync(path.join(MOD, d)).filter(f => /^\d\d-.*\.html$/.test(f)).sort();
|
||
|
|
let sec = 0, chr = 0;
|
||
|
|
for (const f of files) {
|
||
|
|
const t = fs.readFileSync(path.join(MOD, d, f), "utf8");
|
||
|
|
sec += (t.match(/<h3 id="/g) || []).length;
|
||
|
|
const body = (t.match(/<h2 id="[^"]*">[\s\S]*?<\/article>/) || [""])[0];
|
||
|
|
chr += body.replace(/<[^>]+>/g, "").replace(/\s/g, "").length;
|
||
|
|
}
|
||
|
|
tCh += files.length; tSec += sec; tChr += chr;
|
||
|
|
console.log(`${d}\t${files.length}\t${sec}\t${Math.round(chr / 1000)}`);
|
||
|
|
}
|
||
|
|
console.log(`合计\t${tCh}\t${tSec}\t${Math.round(tChr / 1000)}`);
|