feat(route): add 虎扑首页 (#9416)

This commit is contained in:
Ethan Shen
2022-03-29 22:03:13 +08:00
committed by GitHub
parent 763b978c1c
commit d50e0948dc
12 changed files with 292 additions and 234 deletions
+24 -28
View File
@@ -356,47 +356,43 @@ pageClass: routes
## 虎扑
### 虎扑 BBS 论坛
### 首页
<Route author="LogicJake" example="/hupu/bbs/bxj/2" path="/hupu/bbs/:id/:order?" :paramsDesc="['板块 id,可在板块 URL 找到', '排序方式,1最新回帖(默认),2最新发帖,3精华帖']">
<Route author="nczitzk" example="/hupu/nba" path="/hupu/:category?" :paramsDesc="['分类,见下表']">
此路由与旧的 `/hupu/bxj/:id/:order?` 等价,但推荐使用 `/hupu/bbs/:id/:order?`,旧路由可能会在未来被删除。
| NBA | CBA | 足球 |
| --- | --- | ------ |
| nba | cba | soccer |
::: tip 提示
电竞分类参见 [游戏热帖](https://bbs.hupu.com/all-gg) 的对应路由 [`/hupu/all/all-gg`](https://rsshub.app/hupu/all/all-gg)。
:::
</Route>
### 分类
### 社区
<Route author="nczitzk" example="/hupu/all/gambia" path="/hupu/all/:caty" :paramsDesc="['分类名,见下表']">
<Route author="LogicJake nczitzk" example="/hupu/bbs/34" path="/hupu/bbs/:id?/:order?" :paramsDesc="['编号,可在对应社区 URL 中找到,默认为步行街', '排序方式,可选 `0` 即 最新回复 或 `1` 即 最新发布']">
| 分类 | 名称 |
| ------ | -------- |
| NBA 论坛 | nba |
| CBA 论坛 | cba |
| 运动和装备 | gear |
| 国际足球论坛 | soccer |
| 中国足球论坛 | csl |
| 综合体育 | sports |
| 步行街 | gambia |
| 彩票中心 | lottery |
| 自建版块 | boards |
| 虎扑社团 | group |
| 站务管理 | feedback |
::: tip 提示
更多参见 [虎扑社区版块目录](https://bbs.hupu.com/boards.php) 左侧导航栏各板块分类页
更多社区参见 [社区](https://m.hupu.com/bbs)
:::
</Route>
### 子站
### 热帖
<Route author="nczitzk" example="/hupu/dept/nba" path="/hupu/dept/:dept" :paramsDesc="['名称,见下表']">
<Route author="nczitzk" example="/hupu/all/topic-daily" path="/hupu/all/:id?" :paramsDesc="['编号,可在对应热帖版面 URL 中找到,默认为步行街每日话题']">
| 子站 | 名称 |
| ---- | ------------ |
| NBA | nba |
| 国际足球 | soccer |
| 中国足球 | soccer-china |
| CBA | cba |
| 电竞 | gg |
::: tip 提示
更多热帖版面参见 [论坛](https://bbs.hupu.com)
:::
</Route>
+4 -4
View File
@@ -1333,10 +1333,10 @@ router.get('/leetcode/submission/us/:user', lazyloadRouteHandler('./routes/leetc
router.get('/leetcode/submission/cn/:user', lazyloadRouteHandler('./routes/leetcode/check-cn'));
// 虎扑
router.get('/hupu/bxj/:id/:order?', lazyloadRouteHandler('./routes/hupu/bbs'));
router.get('/hupu/bbs/:id/:order?', lazyloadRouteHandler('./routes/hupu/bbs'));
router.get('/hupu/all/:caty', lazyloadRouteHandler('./routes/hupu/all'));
router.get('/hupu/dept/:dept', lazyloadRouteHandler('./routes/hupu/dept'));
// router.get('/hupu/bxj/:id/:order?', lazyloadRouteHandler('./routes/hupu/bbs'));
// router.get('/hupu/bbs/:id/:order?', lazyloadRouteHandler('./routes/hupu/bbs'));
// router.get('/hupu/all/:caty', lazyloadRouteHandler('./routes/hupu/all'));
// router.get('/hupu/dept/:dept', lazyloadRouteHandler('./routes/hupu/dept'));
// 牛客网 migrated to v2
// router.get('/nowcoder/discuss/:type/:order', lazyloadRouteHandler('./routes/nowcoder/discuss'));
-53
View File
@@ -1,53 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://bbs.hupu.com';
const currentUrl = `${rootUrl}/all-${ctx.params.caty}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('div.list ul li')
.slice(0, 20)
.map((_, item) => {
item = $(item);
const a = item.find('span.textSpan a[title]');
return {
title: a.attr('title'),
link: `${rootUrl}${a.attr('href')}`,
};
})
.get();
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
try {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('div.quote-content').html();
item.author = content('div.author div.left a.u').eq(0).text();
item.pubDate = new Date(content('span.stime').eq(0).text() + ' GMT+8').toUTCString();
return item;
} catch (error) {
return Promise.resolve('');
}
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};
-83
View File
@@ -1,83 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
const host = 'https://bbs.hupu.com';
module.exports = async (ctx) => {
const id = ctx.params.id;
const order = ctx.params.order || 1;
let link = `https://bbs.hupu.com/${id}`;
let order_name;
if (parseInt(order) === 1) {
order_name = '最新回帖';
} else if (parseInt(order) === 2) {
order_name = '最新发帖';
link += '-postdate-1';
} else if (parseInt(order) === 3) {
order_name = '精华';
link += '-digest';
}
const response = await got.get(link);
const $ = cheerio.load(response.data);
const type_name = $('span.infoname').text();
const description = $('#des_forum').text();
const list = $('ul.for-list li')
.slice(0, 10)
.map(function () {
const info = {
title: $(this).find('div.titlelink.box > a.truetit').text().trim(),
link: $(this).find('div.titlelink.box > a.truetit').attr('href'),
author: $(this).find('a.aulink').text(),
};
return info;
})
.get();
for (let i = list.length - 1; i >= 0; i--) {
if (!list[i].link.endsWith('html')) {
list.splice(i, 1);
}
}
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const itemUrl = url.resolve(host, info.link);
const author = info.author;
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got.get(itemUrl);
const $ = cheerio.load(response.data);
const date = $('#tpc span.stime').text();
const description = $('div.quote-content').html();
const single = {
title,
link: itemUrl,
author,
description,
pubDate: new Date(date).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `${type_name}${order_name}——虎扑步行街`,
link,
description,
item: out,
};
};
-66
View File
@@ -1,66 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
let currentUrl = '';
if (ctx.params.dept === 'soccer-china') {
currentUrl = `https://soccer.hupu.com/china`;
} else {
currentUrl = `https://${ctx.params.dept}.hupu.com`;
}
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const query = {
nba: 'div.list-item',
soccer: 'div.list-item',
'soccer-china': '#focusNews',
cba: '#focusNews',
gg: 'div.fouce-news',
};
const list = $(query[ctx.params.dept])
.find('a[href!=""]')
.slice(0, 20)
.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 () => {
try {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('div.quote-content').html();
item.author = content('div.author div.left a.u').eq(0).text();
item.pubDate = new Date(content('span.stime').eq(0).text() + ' GMT+8').toUTCString();
return item;
} catch (error) {
return Promise.resolve('');
}
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};
+73
View File
@@ -0,0 +1,73 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate, parseRelativeDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const id = ctx.params.id ?? 'topic-daily';
const rootUrl = 'https://bbs.hupu.com';
const currentUrl = `${rootUrl}/${id}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
let items = $('div.t-info > a, a.p-title')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: `https://m.hupu.com/bbs${item.attr('href')}`,
pubDate: timezone(parseDate(item.parent().parent().find('.post-time').text(), 'MM-DD HH:mm'), +8),
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
try {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
const videos = [];
content('.thread-video-wrap').each(function () {
videos.push(content('video').attr('src'));
content(this).remove();
});
content('.bbs-user-info-time span').remove();
item.author = content('.bbs-user-info-name').first().text();
item.pubDate = item.pubDate ?? timezone(parseRelativeDate(content('.bbs-user-info-time').first().text()), +8);
item.description = art(path.join(__dirname, 'templates/description.art'), {
videos,
description: content('.bbs-thread-content').html(),
});
} catch (e) {
// no-empty
}
return item;
})
)
);
ctx.state.data = {
title: `虎扑社区 - ${$('.middle-title, .bbs-sl-web-intro-detail-title').text()}`,
link: currentUrl,
item: items,
};
};
+64
View File
@@ -0,0 +1,64 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseRelativeDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const id = ctx.params.id ?? '34';
const order = ctx.params.order ?? '1';
const rootUrl = 'https://m.hupu.com';
const currentUrl = `${rootUrl}/api/v1/bbs-forumthreadlist-frontend/${id}-1?postdate=${order}`;
const response = await got({
method: 'get',
url: currentUrl,
});
let items = response.data.data.t_list.map((item) => ({
title: item.title,
link: `${rootUrl}/bbs/${item.tid}.html`,
pubDate: timezone(parseRelativeDate(item.t_post), +8),
}));
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
try {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
const videos = [];
content('.thread-video-wrap').each(function () {
videos.push(content('video').attr('src'));
content(this).remove();
});
item.author = content('.bbs-user-info-name').first().text();
item.description = art(path.join(__dirname, 'templates/description.art'), {
videos,
description: content('#bbs-thread-content').html(),
});
} catch (e) {
// no-empty
}
return item;
})
)
);
ctx.state.data = {
title: `虎扑社区 - ${response.data.data.keywords}`,
link: currentUrl,
item: items,
description: response.data.data.description,
};
};
+72
View File
@@ -0,0 +1,72 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const categories = {
nba: {
title: 'NBA',
data: 'news',
},
cba: {
title: 'CBA',
data: 'news',
},
soccer: {
title: '足球',
data: 'soccerIndexData',
},
};
module.exports = async (ctx) => {
const category = ctx.params.category ?? 'soccer';
const rootUrl = 'https://m.hupu.com';
const currentUrl = `${rootUrl}/${category}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const data = JSON.parse(response.data.match(/"pageProps":(.*)},"page":"\//)[1]);
let items = data[categories[category].data].map((item) => ({
title: item.title,
pubDate: timezone(parseDate(item.publishTime), +8),
link: item.link.replace(/bbs\.hupu.com/, 'm.hupu.com/bbs'),
}));
items = await Promise.all(
items
.filter((item) => !/subject/.test(item.link))
.map((item) =>
ctx.cache.tryGet(item.link, async () => {
try {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.author = content('.bbs-user-info-name').text();
item.description = content('#bbs-thread-content').html();
item.category = content('.bbs-link')
.toArray()
.map((c) => content(c).text());
} catch (e) {
// no-empty
}
return item;
})
)
);
ctx.state.data = {
title: `虎扑 - ${categories[category].title}`,
link: currentUrl,
item: items,
};
};
+7
View File
@@ -0,0 +1,7 @@
module.exports = {
'/all/:id?': ['nczitzk'],
'/bbs/:id?/:order?': ['LogicJake', 'nczitzk'],
'/bxj/:id?/:order?': ['LogicJake', 'nczitzk'],
'/dept/:category?': ['nczitzk'],
'/:category?': ['nczitzk'],
};
+35
View File
@@ -0,0 +1,35 @@
module.exports = {
'hupu.com': {
_name: '虎扑',
'': [
{
title: '首页',
docs: 'https://docs.rsshub.app/bbs.html#hu-pu-shou-ye',
source: ['/:category', '/'],
target: '/hupu/:category',
},
],
bbs: [
{
title: '热帖',
docs: 'https://docs.rsshub.app/bbs.html#hu-pu-re-tie',
source: ['/:id'],
target: '/hupu/all/:id',
},
],
m: [
{
title: '首页',
docs: 'https://docs.rsshub.app/bbs.html#hu-pu-shou-ye',
source: ['/:category', '/'],
target: '/hupu/:category',
},
{
title: '社区',
docs: 'https://docs.rsshub.app/bbs.html#hu-pu-she-qu',
source: ['/bbs/:id', '/'],
target: '/hupu/bbs/:id/:order',
},
],
},
};
+7
View File
@@ -0,0 +1,7 @@
module.exports = function (router) {
router.get('/all/:id?', require('./all'));
router.get('/bbs/:id?/:order?', require('./bbs'));
router.get('/bxj/:id?/:order?', require('./bbs'));
router.get('/dept/:category?', require('./index'));
router.get('/:category?', require('./index'));
};
+6
View File
@@ -0,0 +1,6 @@
{{ if videos }}
{{ each videos video}}
<video><source src="{{ video }}" type="video/mp4"></video>
{{/each}}
{{ /if }}
{{@ description }}