feat(route): add IT之家专题 (#8312)
This commit is contained in:
parent
27979bbd18
commit
ccc7f432e9
|
|
@ -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 桔子
|
||||
|
||||
### 投融资事件
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/zt/:id': ['nczitzk'],
|
||||
};
|
||||
|
|
@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/zt/:id', require('./zt'));
|
||||
};
|
||||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue