diff --git a/docs/bbs.md b/docs/bbs.md index 718394c7f7..9a685895d2 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -429,6 +429,26 @@ pageClass: routes +## 华为心声社区 + +### 华为家事 + + + +分区 ID + +| 全部帖子 | 公司文件 | 管理思考 | 产品改进 | 版务公告 | +| -------- | -------- | -------- | -------- | -------- | +| | 155 | 415 | 427 | 419 | + +排序方式 + +| 最新发帖 | 最新回复 | 最多回复 | 最多点击 | +| -------- | -------- | ---------- | --------- | +| cTime | rTime | replycount | viewcount | + + + ## 一亩三分地 ### 主题帖 diff --git a/lib/router.js b/lib/router.js index c7304a9ec5..5eed4c74b1 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3257,6 +3257,9 @@ router.get('/appsales/:caty?/:time?', require('./routes/appsales/index')); // CGTN router.get('/cgtn/top', require('./routes/cgtn/top')); +// 华为心声社区 +router.get('/huawei/xinsheng/:caty?/:order?/:keyword?', require('./routes/huawei/xinsheng/index')); + // 守望先锋 router.get('/ow/patch', require('./routes/ow/patch')); diff --git a/lib/routes/huawei/xinsheng/index.js b/lib/routes/huawei/xinsheng/index.js new file mode 100644 index 0000000000..794f5d8036 --- /dev/null +++ b/lib/routes/huawei/xinsheng/index.js @@ -0,0 +1,62 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + ctx.params.order = ctx.params.order || ''; + ctx.params.keyword = ctx.params.keyword || ''; + ctx.params.caty = ctx.params.caty || ''; + + const rootUrl = `http://xinsheng.huawei.com/cn/index.php?app=forum&mod=List&class=461&order=${ctx.params.order}&search=${ctx.params.keyword}&cate=${ctx.params.caty}`; + const response = await got({ + method: 'get', + url: rootUrl, + }); + const $ = cheerio.load(response.data); + + $('a[linktag="__subject_link__"]').remove(); + + const list = $('.bbs_list ul li .font_box .title p font a') + .slice(0, 15) + .map((_, item) => { + item = $(item); + return { + title: item.attr('title'), + link: item.attr('href'), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + item.description = content('.bbs_info_right_text').eq(0).html(); + item.pubDate = new Date(content('span.fl').eq(0).text().trim() + ' GMT+8').toUTCString(); + item.author = content('.bbs_info_user_ a').eq(1).text(); + + return item; + }) + ) + ); + + let title; + + $('.bbs_list_box_title_wz ul li').each(function () { + if ($(this).hasClass('on')) { + title = $(this).text(); + return; + } + }); + + ctx.state.data = { + title: `${title} - 华为家事 - 心声社区`, + link: rootUrl, + item: items, + }; +};