mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 23:00:48 +08:00
fix fetch wechat bug
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
// const got = require('@/utils/got');
|
||||
// const cheerio = require('cheerio');
|
||||
const util = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
|
||||
@@ -1,21 +1,32 @@
|
||||
/* eslint-disable no-undef */
|
||||
/* eslint-disable no-case-declarations */
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { finishArticleItem } = require('@/utils/wechat-mp');
|
||||
const { fetchArticle } = require('@/utils/wechat-mp');
|
||||
|
||||
const pageType = (href) => {
|
||||
if (!href.startsWith('http')) {
|
||||
return 'nua';
|
||||
return 'in-nua';
|
||||
}
|
||||
const url = new URL(href);
|
||||
if (url.hostname === 'mp.weixin.qq.com') {
|
||||
return 'wechat-mp';
|
||||
} else if (url.hostname === 'www.nua.edu.cn') {
|
||||
return 'nua';
|
||||
} else {
|
||||
return 'unkonwn';
|
||||
return 'unknown';
|
||||
}
|
||||
};
|
||||
|
||||
function arti_link(text, href) {
|
||||
a = '<a href="' + href + '">' + text + '</a>';
|
||||
a.textContent = text;
|
||||
a.href = href;
|
||||
return a;
|
||||
}
|
||||
|
||||
async function ProcessList(newsUrl, baseUrl, listName, listDate, webPageName) {
|
||||
const result = await got(newsUrl, {
|
||||
https: {
|
||||
@@ -34,7 +45,7 @@ async function ProcessList(newsUrl, baseUrl, listName, listDate, webPageName) {
|
||||
const type = pageType(href);
|
||||
|
||||
return {
|
||||
link: type === 'nua' ? baseUrl + href : href,
|
||||
link: type === 'in-nua' ? baseUrl + href : href,
|
||||
title: item.find('a').attr('title'),
|
||||
pubDate: timezone(parseDate(item.find(listDate).first().text(), 'YYYY-MM-DD'), +8),
|
||||
type,
|
||||
@@ -46,25 +57,26 @@ async function ProcessList(newsUrl, baseUrl, listName, listDate, webPageName) {
|
||||
|
||||
const ProcessFeed = async (items, artiContent, ctx) =>
|
||||
await Promise.all(
|
||||
items.map((item) => {
|
||||
switch (item.type) {
|
||||
case 'nua':
|
||||
return ctx.cache.tryGet(item.link, async () => {
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
switch (item.type) {
|
||||
case 'in-nua' || 'nua':
|
||||
const result = await got({ url: item.link, https: { rejectUnauthorized: false } });
|
||||
const $ = cheerio.load(result.data);
|
||||
item.author = $('.arti_publisher').text() + ' ' + $('.arti_views').text();
|
||||
item.description = $(artiContent).html();
|
||||
return item;
|
||||
});
|
||||
case 'wechat-mp':
|
||||
return finishArticleItem(ctx, items[0]);
|
||||
case 'unkonwn':
|
||||
item.description = `暂不支持解析该文章内容,请点击 ${'阅读原文'.link(item.link)}`;
|
||||
return item;
|
||||
default:
|
||||
return item;
|
||||
}
|
||||
})
|
||||
case 'wechat-mp':
|
||||
return fetchArticle(ctx, item.link);
|
||||
case 'unknown':
|
||||
item.description = `暂不支持解析该内容,请点击 ${arti_link('原文', item.link)}`;
|
||||
return item;
|
||||
default:
|
||||
item.description = `default`;
|
||||
return item;
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user