fix(route/tencent): Circumvent video type link. (#14302)

* fix(route/tencent): Circumvent video type link.

* .
This commit is contained in:
Andvari
2024-01-24 02:35:08 +08:00
committed by GitHub
parent 3154d7a493
commit 716f59e903
+34 -26
View File
@@ -24,34 +24,42 @@ module.exports = async (ctx) => {
const author = item.source;
const abstract = item.abstract;
return ctx.cache.tryGet(itemUrl, async () => {
const response = await got(itemUrl);
const $ = cheerio.load(response.data);
const data = JSON.parse(
$('script:contains("window.DATA")')
.text()
.match(/window\.DATA = ({.+});/)[1]
);
const $data = cheerio.load(data.originContent.text, null, false);
return item.articletype === '4'
? {
title,
description: abstract,
link: itemUrl,
author,
pubDate,
}
: ctx.cache.tryGet(itemUrl, async () => {
const response = await got(itemUrl);
const $ = cheerio.load(response.data);
const data = JSON.parse(
$('script:contains("window.DATA")')
.text()
.match(/window\.DATA = ({.+});/)[1]
);
const $data = cheerio.load(data.originContent.text, null, false);
$data('*')
.contents()
.filter((_, elem) => elem.type === 'comment')
.replaceWith((_, elem) =>
art(path.join(__dirname, '../templates/news/image.art'), {
attribute: elem.data.trim(),
originAttribute: data.originAttribute,
})
);
$data('*')
.contents()
.filter((_, elem) => elem.type === 'comment')
.replaceWith((_, elem) =>
art(path.join(__dirname, '../templates/news/image.art'), {
attribute: elem.data.trim(),
originAttribute: data.originAttribute,
})
);
return {
title,
description: $data.html() || abstract,
link: itemUrl,
author,
pubDate,
};
});
return {
title,
description: $data.html() || abstract,
link: itemUrl,
author,
pubDate,
};
});
})
);