mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-19 01:43:35 +08:00
fix: IT home (#5263)
This commit is contained in:
@@ -908,6 +908,26 @@
|
||||
|
||||
'ithome.com': {
|
||||
_name: 'IT 之家',
|
||||
'.': [
|
||||
{
|
||||
title: '24 小时阅读榜',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia',
|
||||
source: ['', '/*'],
|
||||
target: '/ithome/ranking/24h',
|
||||
},
|
||||
{
|
||||
title: '7 天最热',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia',
|
||||
source: ['', '/*'],
|
||||
target: '/ithome/ranking/7days',
|
||||
},
|
||||
{
|
||||
title: '月榜',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia',
|
||||
source: ['', '/*'],
|
||||
target: '/ithome/ranking/monthly',
|
||||
},
|
||||
],
|
||||
it: [
|
||||
{
|
||||
title: 'IT 资讯',
|
||||
|
||||
+4
-4
@@ -162,11 +162,11 @@ pageClass: routes
|
||||
|
||||
### 热榜
|
||||
|
||||
<Route author="immmortal" example="/ithome/ranking/1" path="/ithome/ranking/:type" :paramsDesc="['类别']">
|
||||
<Route author="immmortal luyuhuang" example="/ithome/ranking/24h" path="/ithome/ranking/:type" :paramsDesc="['类别']" radar="1">
|
||||
|
||||
| 1 | 2 | 3 | 4 |
|
||||
| ------------- | ---- | -------- | ---- |
|
||||
| 24 小时阅读榜 | 周榜 | 7 天热评 | 月榜 |
|
||||
| 24h | 7days | monthly |
|
||||
| ------------- | -------- | ------- |
|
||||
| 24 小时阅读榜 | 7 天最热 | 月榜 |
|
||||
|
||||
</Route>
|
||||
|
||||
|
||||
+1
-1
@@ -2245,7 +2245,7 @@ router.get('/pianyuan/:media?', require('./routes/pianyuan/app'));
|
||||
|
||||
// ITHome
|
||||
router.get('/ithome/:caty', require('./routes/ithome/index'));
|
||||
router.get('/ithome/ranking/:type?', require('./routes/ithome/ranking'));
|
||||
router.get('/ithome/ranking/:type', require('./routes/ithome/ranking'));
|
||||
|
||||
// 巴哈姆特
|
||||
router.get('/bahamut/creation/:author/:category?', require('./routes/bahamut/creation'));
|
||||
|
||||
@@ -1,28 +1,38 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const iconv = require('iconv-lite');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const option = ctx.params.type || '1';
|
||||
const link = `https://www.ithome.com/`;
|
||||
const option = ctx.params.type;
|
||||
|
||||
const response = await got.get(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: 'https://www.ithome.com/block/rank.html',
|
||||
encoding: 'binary',
|
||||
});
|
||||
const content = iconv.decode(Buffer.from(response.data, 'binary'), 'gb2312');
|
||||
const $ = cheerio.load(content);
|
||||
|
||||
const config = {
|
||||
1: '24小时阅读榜',
|
||||
2: '周榜',
|
||||
3: '7天热评',
|
||||
4: '月榜',
|
||||
'24h': '24 小时最热',
|
||||
'7days': '7 天最热',
|
||||
monthly: '月榜',
|
||||
};
|
||||
|
||||
const type2id = {
|
||||
'24h': 'd-1',
|
||||
'7days': 'd-2',
|
||||
monthly: 'd-3',
|
||||
};
|
||||
|
||||
const title = config[option];
|
||||
const id = type2id[option];
|
||||
|
||||
let elem = $('.lst.lst-2.hot-list').find('.bx').first();
|
||||
for (let i = 0; i < Number(option) - 1; ++i) {
|
||||
elem = elem.next();
|
||||
if (!id) {
|
||||
throw Error('Bad type. See <a href="https://docs.rsshub.app/new-media.html#it-zhi-jia">https://docs.rsshub.app/new-media.html#it-zhi-jia</a>');
|
||||
}
|
||||
const list = elem
|
||||
.find('li')
|
||||
|
||||
const list = $(`#${id} > li`)
|
||||
.map(function () {
|
||||
const info = {
|
||||
title: $(this).find('a').text(),
|
||||
@@ -41,8 +51,7 @@ module.exports = async (ctx) => {
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(res.data);
|
||||
const post = content('div#con div.content');
|
||||
const paragraph = post.find('div#paragraph');
|
||||
const paragraph = content('#paragraph');
|
||||
paragraph.find('img[data-original]').each((_, ele) => {
|
||||
ele = $(ele);
|
||||
ele.attr('src', ele.attr('data-original'));
|
||||
@@ -50,7 +59,7 @@ module.exports = async (ctx) => {
|
||||
ele.removeAttr('data-original');
|
||||
});
|
||||
item.description = paragraph.html();
|
||||
item.pubDate = new Date(post.find('span#pubtime_baidu').text() + ' GMT+8').toUTCString();
|
||||
item.pubDate = new Date(content('#pubtime_baidu').text() + ' GMT+8').toUTCString();
|
||||
return item;
|
||||
})
|
||||
)
|
||||
@@ -58,7 +67,7 @@ module.exports = async (ctx) => {
|
||||
|
||||
ctx.state.data = {
|
||||
title: `IT之家-${title}`,
|
||||
link: link,
|
||||
link: 'https://www.ithome.com',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user