refactor(middleware): replace opencc with simplecc-wasm (#7111)

* refactor: replace opencc with simplecc-wasm

* docs: simplecc-wasm docs change

* new yarn.lock
This commit is contained in:
fengkx
2021-03-14 14:21:46 +08:00
committed by GitHub
parent 8a25f4773f
commit ea2e2abb91
5 changed files with 12 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
const entities = require('entities');
const mercury_parser = require('@postlight/mercury-parser');
const cheerio = require('cheerio');
const OpenCC = require('opencc');
const { simplecc } = require('simplecc-wasm');
const got = require('@/utils/got');
const config = require('@/config').value;
@@ -231,12 +231,10 @@ module.exports = async (ctx, next) => {
// opencc
if (ctx.query.opencc) {
const converter = new OpenCC(`${ctx.query.opencc}.json`);
const tasks = ctx.state.data.item.map(async (item) => {
item.title = await converter.convertPromise(item.title);
item.description = await converter.convertPromise(item.description);
ctx.state.data.item.forEach((item) => {
item.title = simplecc(item.title, ctx.query.opencc);
item.description = simplecc(item.description, ctx.query.opencc);
});
await Promise.all(tasks);
}
}
}