fix(route): mtime (#11074)

This commit is contained in:
Tony 2022-10-12 21:18:48 +04:00 committed by GitHub
parent cbe111a000
commit 9be1457ec8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 30 deletions

View File

@ -1543,7 +1543,7 @@ JavDB 有多个备用域名,本路由默认使用永久域名 <https://javdb.c
## 时光网
### 资讯
### 时光新闻
<Route author="TsSmartTT" example="/mtime/news" path="/mtime/news" radar="1" rssbud="1"/>

View File

@ -1,3 +1,3 @@
module.exports = {
'/mtime/news': ['TsSmartTT'],
'/news': ['TsSmartTT'],
};

View File

@ -2,47 +2,51 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const asyncPool = require('tiny-async-pool');
module.exports = async (ctx) => {
const link = 'http://news.mtime.com/';
const response = await got({
method: 'get',
url: link,
const link = 'https://news.mtime.com';
const response = await got(link, {
https: {
rejectUnauthorized: false,
},
});
const $ = cheerio.load(response.data);
const list = $('ul.left-cont.fix li')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('h4 a').text(),
link: item.find('h4 a').attr('href'),
};
});
const items = [];
for await (const item of asyncPool(4, list, (item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got(item.link);
const content = cheerio.load(detailResponse.data);
content('.DRE-subject-wrapper').remove();
item.author = content('.editor').text().replace('编辑:', '');
item.description = content('.body').first().html();
item.pubDate = timezone(parseDate(content('.userCreateTime').text()), 8);
item.category = content('.keyword a')
.toArray()
.map((item) => content(item).text());
return item;
})
.get();
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
content('.DRE-subject-wrapper').remove();
item.author = content('.editor').text().replace('编辑:', '');
item.description = content('.body').first().html();
item.pubDate = timezone(parseDate(content('.userCreateTime').text()), 8);
return item;
})
)
);
)) {
items.push(item);
}
ctx.state.data = {
title: 'Mtime时光网 - 资讯',
title: $('head title').text().trim(),
link,
image: 'http://static1.mtime.cn/favicon.ico',
item: items,
};
};

View File

@ -3,7 +3,7 @@ module.exports = {
_name: '时光网',
news: [
{
title: '资讯',
title: '时光新闻',
docs: 'https://docs.rsshub.app/multimedia.html#shi-guang-wang',
source: '/',
target: '/mtime/news',