chore(deps): replace @postlight/mercury-parser with @postlight/parser (#10862)

This commit is contained in:
Tony
2022-09-23 03:25:56 +08:00
committed by GitHub
parent a0eb4e0c67
commit 30975dd20b
4 changed files with 586 additions and 732 deletions

View File

@@ -1,7 +1,7 @@
const entities = require('entities'); const entities = require('entities');
const cheerio = require('cheerio'); const cheerio = require('cheerio');
const { simplecc } = require('simplecc-wasm'); const { simplecc } = require('simplecc-wasm');
// const got = require('@/utils/got'); const got = require('@/utils/got');
const config = require('@/config').value; const config = require('@/config').value;
const RE2 = require('re2'); const RE2 = require('re2');
@@ -252,17 +252,12 @@ module.exports = async (ctx, next) => {
const parsed_result = await ctx.cache.tryGet(`mercury-cache-${link}`, async () => { const parsed_result = await ctx.cache.tryGet(`mercury-cache-${link}`, async () => {
// if parser failed, return default description and not report error // if parser failed, return default description and not report error
try { try {
mercury_parser = mercury_parser || require('@postlight/mercury-parser'); mercury_parser = mercury_parser || require('@postlight/parser');
// const res = await got(link); const { data: res } = await got(link);
// const $ = cheerio.load(res.data, { const $ = cheerio.load(res);
// xmlMode: true,
// });
const result = await mercury_parser.parse(link, { const result = await mercury_parser.parse(link, {
// html: $.html(), html: $.html(),
headers: {
'User-Agent': config.ua,
},
}); });
return result; return result;
} catch (e) { } catch (e) {

View File

@@ -69,6 +69,7 @@
"remark-parse": "9.0.0", "remark-parse": "9.0.0",
"remark-preset-prettier": "0.5.1", "remark-preset-prettier": "0.5.1",
"remark-stringify": "9.0.1", "remark-stringify": "9.0.1",
"request-promise-native": "1.0.9",
"staged-git-files": "1.3.0", "staged-git-files": "1.3.0",
"string-width": "4.2.3", "string-width": "4.2.3",
"supertest": "6.2.4", "supertest": "6.2.4",
@@ -81,7 +82,7 @@
}, },
"dependencies": { "dependencies": {
"@koa/router": "12.0.0", "@koa/router": "12.0.0",
"@postlight/mercury-parser": "2.2.1", "@postlight/parser": "2.2.2",
"@sentry/node": "7.13.0", "@sentry/node": "7.13.0",
"aes-js": "3.1.2", "aes-js": "3.1.2",
"art-template": "4.13.2", "art-template": "4.13.2",

View File

@@ -313,12 +313,12 @@ describe('wrong_path', () => {
}); });
describe('fulltext_mode', () => { describe('fulltext_mode', () => {
it.skip(`fulltext`, async () => { it(`fulltext`, async () => {
const response = await request.get('/test/1?mode=fulltext'); const response = await request.get('/test/1?mode=fulltext');
expect(response.status).toBe(200); expect(response.status).toBe(200);
const parsed = await parser.parseString(response.text); const parsed = await parser.parseString(response.text);
expect(parsed.items[0].content).not.toBe(undefined); expect(parsed.items[0].content).not.toBe(undefined);
}, 10000); }, 20000);
}); });
describe('complicated_description', () => { describe('complicated_description', () => {

1296
yarn.lock
View File

File diff suppressed because it is too large Load Diff