feat(route): add iThome 台灣新聞 (#10771)

This commit is contained in:
miles 2022-09-13 11:57:07 +00:00 committed by GitHub
parent 06d1d824e9
commit 3159abe9cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 0 deletions

View File

@ -695,6 +695,17 @@ Tag
<Route author="xyqfer" example="/itjuzi/merge" path="/itjuzi/merge"/>
## iThome 台灣
### Feeds
<Route author="miles170" example="/ithome/tw/feeds/news" path="/ithome/tw/feeds/:category" :paramsDesc="['類別']" radar="1">
| 新聞 | AI | Cloud | DevOps | 資安 |
| ---- | -------- | ----- | ------ | -------- |
| news | big-data | cloud | devops | security |
</Route>
## KBS
### News

View File

@ -1,6 +1,7 @@
module.exports = {
'/ranking/:type': ['immmortal', 'luyuhuang'],
'/tag/:name': ['Fatpandac'],
'/tw/feeds/:category': ['miles170'],
'/zt/:id': ['nczitzk'],
'/:caty': ['luyuhuang'],
};

View File

@ -106,4 +106,15 @@ module.exports = {
},
],
},
'ithome.com.tw': {
_name: 'iThome',
www: [
{
title: 'Feeds',
docs: 'https://docs.rsshub.app/new-media.html#ithome-tai-wan',
source: ['/:category', '/:category/feeds'],
target: '/ithome/tw/feeds/:category',
},
],
},
};

View File

@ -1,6 +1,7 @@
module.exports = function (router) {
router.get('/ranking/:type', require('./ranking'));
router.get('/tag/:name', require('./tag'));
router.get('/tw/feeds/:category', require('./tw/feeds'));
router.get('/zt/:id', require('./zt'));
router.get('/:caty', require('./index'));
};

38
lib/v2/ithome/tw/feeds.js Normal file
View File

@ -0,0 +1,38 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const baseUrl = 'https://www.ithome.com.tw';
const currentUrl = `${baseUrl}/${ctx.params.category}/feeds`;
const response = await got(currentUrl);
const $ = cheerio.load(response.data);
const name = $('a.active-trail').text();
const items = await Promise.all(
$('.title a')
.get()
.map((item) => {
const link = baseUrl + $(item).attr('href');
return ctx.cache.tryGet(link, async () => {
const response = await got(link);
const $ = cheerio.load(response.data);
return {
title: $('.page-header').text(),
author: $('.author a').text(),
description: $('article').eq(0).html(),
pubDate: timezone(parseDate($('.created').text(), 'YYYY-MM-DD'), +8),
category: name,
link,
};
});
})
);
ctx.state.data = {
title: `${name} | iThome`,
link: currentUrl,
description: 'iThome Online 是臺灣第一個網路原生報提供IT產業即時新聞、企業IT產品報導與測試、技術專題、IT應用報導、IT書訊以及面向豐富的名家專欄。',
item: items,
};
};