feat: support opencc

This commit is contained in:
DIYgod
2020-09-25 01:30:52 +08:00
parent 05684aa351
commit 752ee212a9
3 changed files with 25 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
const he = require('he');
const mercury_parser = require('@postlight/mercury-parser');
const cheerio = require('cheerio');
const OpenCC = require('opencc');
const got = require('@/utils/got');
const config = require('@/config').value;
@@ -224,6 +225,16 @@ module.exports = async (ctx, next) => {
return item;
});
}
// 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);
});
await Promise.all(tasks);
}
}
}
};