diff --git a/docs/bbs.md b/docs/bbs.md index 2783a08f5c..86d225a45b 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -552,11 +552,11 @@ pageClass: routes ### 社区 - + ::: tip 提示 -更多社区参见 [社区](https://m.hupu.com/bbs) +更多社区参见 [社区](https://bbs.hupu.com) ::: diff --git a/lib/v2/hupu/bbs.js b/lib/v2/hupu/bbs.js index 1829cc1d46..334ea0cca8 100644 --- a/lib/v2/hupu/bbs.js +++ b/lib/v2/hupu/bbs.js @@ -1,27 +1,35 @@ 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'); +const { parseDate } = require('@/utils/parse-date'); 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 rootUrl = 'https://bbs.hupu.com'; + const currentUrl = `${rootUrl}/${id}${order === '1' ? `-postdate` : ''}`; 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), - })); + const $ = cheerio.load(response.data); + + $('.page-icon').remove(); + + let items = $('.bbs-sl-web-post-layout .post-title a') + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.text(), + link: `${rootUrl}${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) => @@ -34,18 +42,10 @@ module.exports = async (ctx) => { const content = cheerio.load(detailResponse.data); - const videos = []; + content('.seo-dom').remove(); - 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(), - }); + item.author = content('.post-user-comp-info-top-name').first().text(); + item.description = content('.main-thread').first().html(); } catch (e) { // no-empty } @@ -56,9 +56,9 @@ module.exports = async (ctx) => { ); ctx.state.data = { - title: `虎扑社区 - ${response.data.data.keywords}`, + title: `虎扑社区 - ${$('.bbs-sl-web-intro-detail-title').text()}`, link: currentUrl, item: items, - description: response.data.data.description, + description: $('.bbs-sl-web-intro-detail-desc-text').first().text(), }; }; diff --git a/lib/v2/hupu/templates/description.art b/lib/v2/hupu/templates/description.art deleted file mode 100644 index 73610b2e60..0000000000 --- a/lib/v2/hupu/templates/description.art +++ /dev/null @@ -1,6 +0,0 @@ -{{ if videos }} -{{ each videos video}} - -{{/each}} -{{ /if }} -{{@ description }} \ No newline at end of file