fix(route): wxkol link (#12799)
* fix(route): wxkol link * fix(core): fix wechat-mp date parsing `var ct = "timestamp"` can appear after `var ct=function()`
This commit is contained in:
parent
cb7ea448b9
commit
1de2457216
|
|
@ -213,7 +213,7 @@ const fetchArticle = (ctx, url, bypassHostCheck = false) => {
|
|||
}
|
||||
|
||||
let pubDate;
|
||||
const publish_time_script = $('script[nonce][type="text/javascript"]:contains("var ct")').first().html();
|
||||
const publish_time_script = $('script[nonce][type="text/javascript"]:contains("var ct")').text();
|
||||
const publish_time_match = publish_time_script && publish_time_script.match(/var ct *= *"?(\d{10})"?/);
|
||||
const publish_timestamp = publish_time_match && publish_time_match[1];
|
||||
if (publish_timestamp) {
|
||||
|
|
|
|||
|
|
@ -1,22 +1,13 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { fetchArticle } = require('@/utils/wechat-mp');
|
||||
const { finishArticleItem } = require('@/utils/wechat-mp');
|
||||
const config = require('@/config').value;
|
||||
const asyncPool = require('tiny-async-pool');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const baseUrl = 'https://www.wxkol.com';
|
||||
const { id } = ctx.params;
|
||||
const url = `${baseUrl}/show/${id}.html`;
|
||||
|
||||
const asyncPoolAll = async (...args) => {
|
||||
const results = [];
|
||||
for await (const result of asyncPool(...args)) {
|
||||
results.push(result);
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
const feedData = await ctx.cache.tryGet(
|
||||
url,
|
||||
async () => {
|
||||
|
|
@ -30,13 +21,13 @@ module.exports = async (ctx) => {
|
|||
const a = item.find('.title a');
|
||||
return {
|
||||
title: a.attr('title'),
|
||||
link: `${baseUrl}${a.attr('href')}`,
|
||||
link: a.attr('href'),
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
feedTitle: $('head title').text(),
|
||||
feedDescription: $('head description').text(),
|
||||
feedDescription: $('.info_left .description i').text(),
|
||||
feedImage: $('.main .logo .avatar')
|
||||
.attr('style')
|
||||
.match(/url\('(.+)'\)/)[1],
|
||||
|
|
@ -47,34 +38,14 @@ module.exports = async (ctx) => {
|
|||
false
|
||||
);
|
||||
|
||||
const urlList = await asyncPoolAll(2, feedData.feedItem, (item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const { data: response } = await got(item.link);
|
||||
const $ = cheerio.load(response);
|
||||
item.link = `${baseUrl}${$('.source a').attr('href')}`;
|
||||
return item;
|
||||
})
|
||||
);
|
||||
|
||||
const items = await asyncPoolAll(4, urlList, async (item) => {
|
||||
const { title, author, description, summary, pubDate, mpName, link: itemLink } = await fetchArticle(ctx, item.link, true);
|
||||
|
||||
item.title = title;
|
||||
item.author = author;
|
||||
item.description = description;
|
||||
item.summary = summary;
|
||||
item.pubDate = pubDate;
|
||||
item.author = mpName;
|
||||
item.link = itemLink;
|
||||
|
||||
return item;
|
||||
});
|
||||
const items = await Promise.all(feedData.feedItem.map((item) => finishArticleItem(ctx, item)));
|
||||
|
||||
ctx.state.data = {
|
||||
title: feedData.feedTitle,
|
||||
description: feedData.feedDescription,
|
||||
link: url,
|
||||
image: feedData.feedImage,
|
||||
icon: feedData.feedImage,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue