From fa7cabe7972e4ef70e687dd70a33cc281e71974c Mon Sep 17 00:00:00 2001 From: TheLittle_Yang <2570984321@qq.com> Date: Fri, 30 Jun 2023 00:04:42 +0800 Subject: [PATCH] feat(route): add xboxfan.com (#12717) * add xboxfan.com * Create radar.js * Update news.js * Update lib/v2/xboxfan/radar.js * remove trailing whitespace * Apply suggestions from code review --------- --- docs/game.md | 6 +++++ lib/v2/xboxfan/maintainer.js | 3 +++ lib/v2/xboxfan/news.js | 45 ++++++++++++++++++++++++++++++++++++ lib/v2/xboxfan/radar.js | 13 +++++++++++ lib/v2/xboxfan/router.js | 3 +++ 5 files changed, 70 insertions(+) create mode 100644 lib/v2/xboxfan/maintainer.js create mode 100644 lib/v2/xboxfan/news.js create mode 100644 lib/v2/xboxfan/radar.js create mode 100644 lib/v2/xboxfan/router.js diff --git a/docs/game.md b/docs/game.md index 7dc51fc15..bca386100 100644 --- a/docs/game.md +++ b/docs/game.md @@ -623,6 +623,12 @@ News 的数据来自 +## 盒心光环 + +### 资讯 + + + ## 剑网 3 ### 新闻资讯 diff --git a/lib/v2/xboxfan/maintainer.js b/lib/v2/xboxfan/maintainer.js new file mode 100644 index 000000000..70897f8fa --- /dev/null +++ b/lib/v2/xboxfan/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news': ['XXY233'], +}; diff --git a/lib/v2/xboxfan/news.js b/lib/v2/xboxfan/news.js new file mode 100644 index 000000000..fab89af9d --- /dev/null +++ b/lib/v2/xboxfan/news.js @@ -0,0 +1,45 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseRelativeDate } = require('@/utils/parse-date'); +const md5 = require('@/utils/md5'); + +module.exports = async (ctx) => { + const baseUrl = 'https://xboxfan.com/'; + const { data: response } = await got(baseUrl); + const $ = cheerio.load(response); + + $('div.homeCom').remove(); + $('div.homeMore').remove(); + + $('el-image').each((index, el_image) => { + const img = $(''); + img.attr('src', $(el_image).attr('src')); + $(el_image).replaceWith(img); + }); + + const items = $(`div.homeItem[v-if="showFeedLevel == 'read'"]`) + .toArray() + .map((item) => { + const data = { + title: '资讯', + author: $(item).find('div.homeName').text(), + pubDate: parseRelativeDate($(item).find('div.homeTime').first().text().split(' ')[0]), + }; + + $(item).find('div.homeName').remove(); + $(item).find('div.homeTime').remove(); + + const md5Value = md5($(item).text()); + data.guid = md5Value; + + data.description = $(item).html(); + + return data; + }); + + ctx.state.data = { + title: '盒心光环·资讯', + link: 'https://xboxfan.com/', + item: items, + }; +}; diff --git a/lib/v2/xboxfan/radar.js b/lib/v2/xboxfan/radar.js new file mode 100644 index 000000000..33cdd1ae4 --- /dev/null +++ b/lib/v2/xboxfan/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'xboxfan.com': { + _name: '盒心光环', + '.': [ + { + title: '资讯', + docs: 'https://docs.rsshub.app/game.html#he-xin-guang-huan', + source: '/', + target: '/xboxfan/news', + }, + ], + }, +}; diff --git a/lib/v2/xboxfan/router.js b/lib/v2/xboxfan/router.js new file mode 100644 index 000000000..630036b8e --- /dev/null +++ b/lib/v2/xboxfan/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/news', require('./news')); +};