fix(route): 生物探索 (#8098)

This commit is contained in:
Aidi Stan
2021-10-05 17:39:00 +08:00
committed by GitHub
parent ba94b34e9a
commit e09393e15d
8 changed files with 71 additions and 54 deletions

View File

@@ -63,11 +63,11 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more
### Channel
<Route author="aidistan" example="/biodiscover" path="/biodiscover/:channel?" :paramsDesc="['channel, see below, `home` by default']">
<Route author="aidistan" example="/biodiscover" path="/biodiscover/:channel" :paramsDesc="['channel, see below']">
| Home | Research | Industry | Financing | Politics | Celebrity | Company | Product | Activity |
| ---- | -------- | -------- | --------- | -------- | --------- | ------- | ------- | -------- |
| home | research | industry | financing | politics | celebrity | company | product | activity |
| Research | Interview | Industry | Activity |
| -------- | --------- | -------- | -------- |
| reaseach | interview | industry | activity |
</Route>

View File

@@ -2106,11 +2106,11 @@ column 为 third 时可选的 category:
### 频道
<Route author="aidistan" example="/biodiscover" path="/biodiscover/:channel?" :paramsDesc="['频道,见下表,默认为首页']">
<Route author="aidistan" example="/biodiscover" path="/biodiscover/:channel" :paramsDesc="['频道,见下表']">
| 首页 | 研究 | 产业 | 融资 | 时政 | 人物 | 公司 | 新品 | 活动 |
| ---- | -------- | -------- | --------- | -------- | --------- | ------- | ------- | -------- |
| home | research | industry | financing | politics | celebrity | company | product | activity |
| 最新研究 | 人物访谈 | 产业动态 | 活动发布 |
| -------- | --------- | -------- | -------- |
| reaseach | interview | industry | activity |
</Route>

View File

@@ -4203,9 +4203,6 @@ router.get('/x410/news', lazyloadRouteHandler('./routes/x410/news'));
// 恩山无线论坛
router.get('/right/forum/:id?', lazyloadRouteHandler('./routes/right/forum'));
// 生物探索
router.get('/biodiscover/:channel?', lazyloadRouteHandler('./routes/biodiscover'));
// 香港經濟日報
router.get('/hket/:category?', lazyloadRouteHandler('./routes/hket/index'));

View File

@@ -1,43 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseRelativeDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const channel = ctx.params.channel || 'home';
const listUrl = 'http://www.biodiscover.com' + (channel === 'home' ? '/' : '/news/' + channel);
const response = await got({ url: listUrl });
const $ = cheerio.load(response.data);
const listTitle = $('.list-title').text().trim();
const itemUrls = $('.news_list li h2 a')
.map((_, item) => 'http://www.biodiscover.com' + $(item).attr('href'))
.toArray();
ctx.state.data = {
title: '生物探索' + (listTitle ? ` - ${listTitle}` : ''),
link: listUrl,
description: $('meta[name=description]').attr('content'),
item: await Promise.all(
itemUrls.map((itemUrl) =>
ctx.cache.tryGet(itemUrl, async () => {
const detailResponse = await got({ url: itemUrl });
const $ = cheerio.load(detailResponse.data);
const dateStr = $('.from').children().last().text().replace('·', '').trim();
return {
title: $('.article_title').text(),
author: $('.from').children().first().text().trim(),
category: $('.article .share .tag a')
.map((_, a) => $(a).text().trim())
.toArray(),
description: $('.article .main_info').html(),
pubDate: timezone(parseRelativeDate(dateStr) || new Date(dateStr), +8),
link: itemUrl,
};
})
)
),
};
};

View File

@@ -0,0 +1,44 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const channel = ctx.params.channel;
const listUrl = 'http://www.biodiscover.com/' + channel;
const response = await got({ url: listUrl });
const $ = cheerio.load(response.data);
const items = $('.new_list .newList_box')
.map((_, item) => ({
pubDate: parseDate($(item).find('.news_flow_tag .times').text().trim()),
link: 'http://www.biodiscover.com' + $(item).find('h2 a').attr('href'),
}))
.toArray();
ctx.state.data = {
title: '生物探索 - ' + $('.header li.sel a').text(),
link: listUrl,
description: $('meta[name=description]').attr('content'),
item: await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({ url: item.link });
const $ = cheerio.load(detailResponse.data);
// remove sharing info if exists
const lastNode = $('.main_info').children().last();
if (lastNode.css('display') === 'none') {
lastNode.remove();
}
return {
title: $('h1').text().trim(),
description: $('.main_info').html(),
pubDate: item.pubDate,
link: item.link,
};
})
)
),
};
};

View File

@@ -0,0 +1,3 @@
module.exports = {
'/:channel?': ['aidistan'],
};

View File

@@ -0,0 +1,13 @@
module.exports = {
'biodiscover.com': {
_name: '生物探索',
www: [
{
title: '频道',
docs: 'https://docs.rsshub.app/new-media.html#sheng-wu-tan-suo',
source: '/:channel',
target: '/biodiscover/:channel',
},
],
},
};

View File

@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:channel?', require('./index'));
};