fix(route): 果壳网科学人 (#9531)

* fix(route): 果壳网科学人

* ref: use got instead of got.get

* ref: rename channel.js
This commit is contained in:
Ethan Shen
2022-04-13 17:50:11 +08:00
committed by GitHub
parent d63ece212f
commit 6f98d3cee6
7 changed files with 35 additions and 8 deletions
+1 -1
View File
@@ -1995,7 +1995,7 @@ others = 热点新闻 + 滚动新闻
### 科学人
<Route author="alphardex" example="/guokr/scientific" path="/guokr/scientific"/>
<Route author="alphardex nczitzk" example="/guokr/scientific" path="/guokr/scientific"/>
### 果壳网专栏
+2 -2
View File
@@ -813,8 +813,8 @@ router.get('/xmu/aero/:type', lazyloadRouteHandler('./routes/universities/xmu/ae
router.get('/ifanr/:channel?', lazyloadRouteHandler('./routes/ifanr/index'));
// 果壳网
router.get('/guokr/scientific', lazyloadRouteHandler('./routes/guokr/scientific'));
router.get('/guokr/:channel', lazyloadRouteHandler('./routes/guokr/calendar'));
// router.get('/guokr/scientific', lazyloadRouteHandler('./routes/guokr/scientific'));
// router.get('/guokr/:channel', lazyloadRouteHandler('./routes/guokr/calendar'));
// 联合早报 已经迁移至v2模板
// router.get('/zaobao/realtime/:section?', require('./routes/zaobao/realtime'));
@@ -3,7 +3,7 @@ const got = require('@/utils/got');
async function loadFullPage(ctx, id) {
const link = `https://apis.guokr.com/minisite/article/${id}.json`;
const content = await ctx.cache.tryGet(link, async () => {
const res = await got.get(link);
const res = await got(link);
return res.data.result.content;
});
return content;
@@ -19,7 +19,7 @@ const channelMap = {
module.exports = async (ctx) => {
const channel = channelMap[ctx.params.channel] ? channelMap[ctx.params.channel] : ctx.params.channel;
const response = await got.get(`https://www.guokr.com/apis/minisite/article.json?retrieve_type=by_wx&channel_key=${channel}&offset=0&limit=10`);
const response = await got(`https://www.guokr.com/apis/minisite/article.json?retrieve_type=by_wx&channel_key=${channel}&offset=0&limit=10`);
const items = response.data.result;
if (items.length === 0) {
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
'/scientific': ['alphardex', 'nczitzk'],
'/:channel': ['DHPO', 'hoilc'],
};
+19
View File
@@ -0,0 +1,19 @@
module.exports = {
'guokr.com': {
_name: '果壳网',
'.': [
{
title: '科学人',
docs: 'https://docs.rsshub.app/new-media.html#guo-ke-wang-ke-xue-ren',
source: ['/scientific', '/'],
target: '/guokr/scientific',
},
{
title: '专栏',
docs: 'https://docs.rsshub.app/new-media.html#guo-ke-wang-zhuan-lan',
source: ['/'],
target: '/guokr/:channel',
},
],
},
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = function (router) {
router.get('/scientific', require('./scientific'));
router.get('/:channel', require('./channel'));
};
@@ -2,7 +2,7 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const response = await got.get('https://www.guokr.com/apis/minisite/article.json?retrieve_type=by_subject&limit=20&offset=0');
const response = await got('https://www.guokr.com/apis/minisite/article.json?retrieve_type=by_subject&limit=20&offset=0');
const result = response.data.result;
@@ -13,9 +13,9 @@ module.exports = async (ctx) => {
item: await Promise.all(
result.map((item) =>
ctx.cache.tryGet(item.url, async () => {
const res = await got.get(item.url);
const res = await got(item.url);
const $ = cheerio.load(res.data);
item.description = $('.eflYNZ #js_content').css('visibility', 'visible').html() || $('.bPfFQI').html();
item.description = $('.eflYNZ #js_content').css('visibility', 'visible').html() ?? $('.bxHoEL').html();
return {
title: item.title,
description: item.description,