forked from OI-wiki/OI-wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_math.js
28 lines (23 loc) · 913 Bytes
/
render_math.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const Promise = require('bluebird');
const { join, dirname } = require('path');
const { green } = require('chalk');
const { listDir } = require('hexo-fs');
const { cpus } = require('os');
const WorkerPool = require('./worker-pool');
const distDir = join(dirname(__dirname) + '/site');
const workerPath = join(__dirname + '/render_math_worker.js');
// Maxmize CPU performance
const cpuNums = cpus().length;
console.log(`${green('INFO')} ${cpuNums} CPU Threads detected, using ${cpuNums} threads`);
const pool = new WorkerPool(workerPath, cpuNums);
const START_TIME = +new Date();
Promise.all(listDir(distDir).map(async item => {
if (item.endsWith('.html')) {
const filename = join(distDir, item);
await pool.run(filename);
}
})).then(() => {
pool.destroy();
const END_TIME = +new Date();
console.log(`${green('INFO')} MathJax rendered finished in ${(END_TIME - START_TIME) / 1000}s.`);
})