feat(route): add IT之家专题 (#8312)

This commit is contained in:
Ethan Shen 2021-11-27 16:01:02 +08:00 committed by GitHub
parent 27979bbd18
commit ccc7f432e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 81 additions and 0 deletions

View File

@ -520,6 +520,14 @@ Tag
</Route>
### 专题
<Route author="nczitzk" example="/ithome/zt/xijiayi" path="/ithome/zt/:id" :paramsDesc="['专题 id']" radar="1" rssbud="1">
所有专题请见[此处](https://www.ithome.com/zt)
</Route>
## IT 桔子
### 投融资事件

View File

@ -0,0 +1,3 @@
module.exports = {
'/zt/:id': ['nczitzk'],
};

13
lib/v2/ithome/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'ithome.com': {
_name: 'IT之家',
'.': [
{
title: '专题',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-zhuan-ti',
source: ['/zt/:id'],
target: '/ithome/zt/:id',
},
],
},
};

3
lib/v2/ithome/router.js Normal file
View File

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

54
lib/v2/ithome/zt.js Normal file
View File

@ -0,0 +1,54 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const id = ctx.params.id;
const rootUrl = 'https://www.ithome.com';
const currentUrl = `${rootUrl}/zt/${id}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.newsbody a')
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
})
.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);
item.description = content('.post_content').html();
item.author = content('#author_baidu').text().replace('作者:', '');
item.pubDate = timezone(parseDate(content('#pubtime_baidu').text()), +8);
return item;
})
)
);
ctx.state.data = {
title: `${$('title').text()} - IT之家`,
link: currentUrl,
item: items,
};
};