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);
}
}
}
};

View File

@@ -99,6 +99,7 @@
"mailparser": "3.0.0",
"markdown-it": "11.0.1",
"module-alias": "2.2.2",
"opencc": "1.1.1",
"parse-torrent": "7.1.3",
"pidusage": "2.0.21",
"plist": "3.0.1",

View File

@@ -8564,6 +8564,11 @@ nan@^2.12.1, nan@^2.14.0:
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c"
integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==
nan@^2.14.1:
version "2.14.1"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.1.tgz#d7be34dfa3105b91494c3147089315eff8874b01"
integrity sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==
nanomatch@^1.2.9:
version "1.2.13"
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
@@ -9022,6 +9027,14 @@ only@~0.0.2:
resolved "https://registry.yarnpkg.com/only/-/only-0.0.2.tgz#2afde84d03e50b9a8edc444e30610a70295edfb4"
integrity sha1-Kv3oTQPlC5qO3EROMGEKcCle37Q=
opencc@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/opencc/-/opencc-1.1.1.tgz#94776e515ef13b23e00065caa04a69e9529d460e"
integrity sha512-t/4FIL43esdrUDfQejqHPhZyWdDVRfwMxsNBkA/2NjIEQv33mG80WHXcmEJ+KMd6T8bjbtx+EiJzPiybE8SPeg==
dependencies:
nan "^2.14.1"
node-pre-gyp "^0.14.0"
opencollective-postinstall@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.2.tgz#5657f1bede69b6e33a45939b061eb53d3c6c3a89"