feat(route): ithome add win11, route of tag and refactor to V2 (#9102)

This commit is contained in:
Fatpandac 2022-02-15 20:24:15 +08:00 committed by GitHub
parent b6229bf987
commit 752a5ebab0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 161 additions and 96 deletions

View File

@ -563,9 +563,9 @@ Tag
<Route author="luyuhuang" example="/ithome/it" path="/ithome/:caty" :paramsDesc="['类别']" radar="1" rssbud="1">
| it | soft | win10 | iphone | ipad | android | digi | next |
| ------- | -------- | ---------- | ----------- | --------- | ------------ | -------- | -------- |
| IT 资讯 | 软件之家 | win10 之家 | iphone 之家 | ipad 之家 | android 之家 | 数码之家 | 智能时代 |
| it | soft | win10 | win11 | iphone | ipad | android | digi | next |
| ------- | -------- | ---------- | ---------- | ----------- | --------- | ------------ | -------- | -------- |
| IT 资讯 | 软件之家 | win10 之家 | win11 之家 | iphone 之家 | ipad 之家 | android 之家 | 数码之家 | 智能时代 |
</Route>
@ -587,6 +587,10 @@ Tag
</Route>
### 标签
<Route author="Fatpandac" example="/ithome/tag/win11" path="/ithome/tag/:name" :paramsDesc="['标签名称,可从网址链接中获取']" radar="1" rssbud="1"/>
## IT 桔子
### 投融资事件

View File

@ -975,94 +975,6 @@ module.exports = {
],
},
'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 资讯',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia',
source: '/',
target: '/ithome/it',
},
],
soft: [
{
title: '软件之家',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia',
source: '/',
target: '/ithome/soft',
},
],
win10: [
{
title: 'win10 之家',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia',
source: '/',
target: '/ithome/win10',
},
],
iphone: [
{
title: 'iphone 之家',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia',
source: '/',
target: '/ithome/iphone',
},
],
ipad: [
{
title: 'ipad 之家',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia',
source: '/',
target: '/ithome/ipad',
},
],
android: [
{
title: 'android 之家',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia',
source: '/',
target: '/ithome/android',
},
],
digi: [
{
title: '数码之家',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia',
source: '/',
target: '/ithome/digi',
},
],
next: [
{
title: '智能时代',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia',
source: '/',
target: '/ithome/next',
},
],
},
'govopendata.com': {
_name: '新闻联播文字版',
cn: [

View File

@ -2353,10 +2353,6 @@ router.get('/nyaa/search/:query?', lazyloadRouteHandler('./routes/nyaa/search'))
// 片源网
router.get('/pianyuan/:media?', lazyloadRouteHandler('./routes/pianyuan/app'));
// ITHome
router.get('/ithome/:caty', lazyloadRouteHandler('./routes/ithome/index'));
router.get('/ithome/ranking/:type', lazyloadRouteHandler('./routes/ithome/ranking'));
// 巴哈姆特
router.get('/bahamut/creation/:author/:category?', lazyloadRouteHandler('./routes/bahamut/creation'));
router.get('/bahamut/creation_index/:category?/:subcategory?/:type?', lazyloadRouteHandler('./routes/bahamut/creation_index'));

View File

@ -13,6 +13,9 @@ const config = {
win10: {
title: 'win10 之家',
},
win11: {
title: 'win11 之家',
},
iphone: {
title: 'iphone 之家',
},

View File

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

View File

@ -1,13 +1,109 @@
module.exports = {
'ithome.com': {
_name: 'IT之家',
_name: 'IT 之家',
'.': [
{
title: '标签',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-zhuan-ti',
source: ['/tag/:name'],
target: '/ithome/tag/:name',
},
{
title: '专题',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-zhuan-ti',
source: ['/zt/:id'],
target: '/ithome/zt/:id',
},
{
title: '24 小时阅读榜',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-re-bang',
source: ['', '/*'],
target: '/ithome/ranking/24h',
},
{
title: '7 天最热',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-re-bang',
source: ['', '/*'],
target: '/ithome/ranking/7days',
},
{
title: '月榜',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-re-bang',
source: ['', '/*'],
target: '/ithome/ranking/monthly',
},
],
it: [
{
title: 'IT 资讯',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-fen-lei-zi-xun',
source: '/',
target: '/ithome/it',
},
],
soft: [
{
title: '软件之家',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-fen-lei-zi-xun',
source: '/',
target: '/ithome/soft',
},
],
win10: [
{
title: 'win10 之家',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-fen-lei-zi-xun',
source: '/',
target: '/ithome/win10',
},
],
win11: [
{
title: 'win11 之家',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-fen-lei-zi-xun',
source: '/',
target: '/ithome/win11',
},
],
iphone: [
{
title: 'iphone 之家',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-fen-lei-zi-xun',
source: '/',
target: '/ithome/iphone',
},
],
ipad: [
{
title: 'ipad 之家',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-fen-lei-zi-xun',
source: '/',
target: '/ithome/ipad',
},
],
android: [
{
title: 'android 之家',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-fen-lei-zi-xun',
source: '/',
target: '/ithome/android',
},
],
digi: [
{
title: '数码之家',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-fen-lei-zi-xun',
source: '/',
target: '/ithome/digi',
},
],
next: [
{
title: '智能时代',
docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-fen-lei-zi-xun',
source: '/',
target: '/ithome/next',
},
],
},
};

View File

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

48
lib/v2/ithome/tag.js Normal file
View File

@ -0,0 +1,48 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const rootUrl = 'https://www.ithome.com/';
module.exports = async (ctx) => {
const name = ctx.params.name;
const url = `${rootUrl}/tag/${name}`;
const response = await got(url);
const $ = cheerio.load(response.data);
const list = $('ul.bl > li')
.map((_, item) => ({
title: $(item).find('h2 > a').text(),
link: $(item).find('h2 > a').attr('href'),
pubDate: timezone(parseDate($(item).find('div.c').attr('data-ot')), +8),
}))
.get();
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got(item.link);
const content = cheerio.load(detailResponse.data);
const article = content('div.post_content');
article.find('img[data-original]').each((_, ele) => {
ele = $(ele);
ele.attr('src', ele.attr('data-original'));
ele.removeAttr('class');
ele.removeAttr('data-original');
});
item.description = article.html();
item.author = content('span.author_baidu > strong').text();
return item;
})
)
);
ctx.state.data = {
title: `IT之家 - ${name}标签`,
link: url,
item: items,
};
};