diff --git a/docs/new-media.md b/docs/new-media.md index 1eba0ecb242df0..bfc496e4338360 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -3714,12 +3714,12 @@ column 为 third 时可选的 category: ### 新闻 - + ### 分类 +:paramsDesc="['新闻类型,类型可在URL中找到,类似`policy`,`eye`等,空或其他任意值展示最新新闻']"/> ## 亿欧网 diff --git a/lib/router.js b/lib/router.js index 2054f1034b6b9a..1c34a66378400a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1265,9 +1265,9 @@ router.get('/xiaoheihe/discount/:platform?', lazyloadRouteHandler('./routes/xiao // 惠誉评级 router.get('/fitchratings/site/:type', lazyloadRouteHandler('./routes/fitchratings/site')); -// 移动支付 -router.get('/mpaypass/news', lazyloadRouteHandler('./routes/mpaypass/news')); -router.get('/mpaypass/main/:type?', lazyloadRouteHandler('./routes/mpaypass/main')); +// 移动支付 migrated to v2 +// router.get('/mpaypass/news', lazyloadRouteHandler('./routes/mpaypass/news')); +// router.get('/mpaypass/main/:type?', lazyloadRouteHandler('./routes/mpaypass/main')); // 新浪科技探索 router.get('/sina/discovery/:type', lazyloadRouteHandler('./routes/sina/discovery')); diff --git a/lib/routes/mpaypass/news.js b/lib/routes/mpaypass/news.js deleted file mode 100644 index 49defa6e6e2d8c..00000000000000 --- a/lib/routes/mpaypass/news.js +++ /dev/null @@ -1,43 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const link = `http://m.mpaypass.com.cn/`; - const listData = await got.get(link); - const $list = cheerio.load(listData.data); - ctx.state.data = { - title: `新闻 - 移动支付网`, - link, - item: await Promise.all( - $list('.newsbodylist') - .map(async (_, el) => { - const $el = $list(el); - const $a = $el.find('.newsbodylist-title a'); - const href = $a.attr('href'); - const title = $a.text(); - const date = $el.find('.newsbodylist-title span').text().split('|')[1]; - - const key = href; - let description; - const value = await ctx.cache.get(key); - - if (value) { - description = value; - } else { - const contentData = await got.get(href); - const $content = cheerio.load(contentData.data); - description = $content('.newsbody').html(); - ctx.cache.set(key, description); - } - - return { - title, - description, - link: href, - pubDate: new Date(date).toUTCString(), - }; - }) - .get() - ), - }; -}; diff --git a/lib/routes/mpaypass/main.js b/lib/v2/mpaypass/main.js similarity index 52% rename from lib/routes/mpaypass/main.js rename to lib/v2/mpaypass/main.js index 8673b7bb80d46b..7d337de39d772e 100644 --- a/lib/routes/mpaypass/main.js +++ b/lib/v2/mpaypass/main.js @@ -1,5 +1,7 @@ -const got = require('../../utils/got'); +const got = require('@/utils/got'); const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); module.exports = async (ctx) => { let title_url = ''; @@ -29,40 +31,34 @@ module.exports = async (ctx) => { .map(function () { const info = { title: $(this).find('#title').text(), - link: $(this).find('#pic a').attr('href'), - pic: $(this).find('#pic img').attr('src'), + link: $(this).find('#title').find('a').attr('href'), time: $(this).find('#time').text(), + category: $(this) + .find('#keywords') + .find('a') + .toArray() + .map((e) => $(e).text().trim()), }; return info; }) .get(); const out = await Promise.all( - list.map(async (info) => { - const title = info.title; - let date = info.time.toString(); - date = date.substring(2, date.length); - const link = info.link; + list.map((info) => + ctx.cache.tryGet(info.link, async () => { + const response = await got(info.link); + const $ = cheerio.load(response.data); + const newsbody = $('div.newsbody').html(); - const cache = await ctx.cache.get(link); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - - const response = await got.get(link); - const $ = cheerio.load(response.data); - const newsbody = $('div.newsbody').html(); - - const single = { - title, - link, - pubDate: date, - description: newsbody, - }; - - ctx.cache.set(link, JSON.stringify(single)); - return Promise.resolve(single); - }) + return { + title: info.title, + link: info.link, + pubDate: timezone(parseDate(info.time), +8), + description: newsbody, + category: info.category, + }; + }) + ) ); ctx.state.data = { diff --git a/lib/v2/mpaypass/maintainer.js b/lib/v2/mpaypass/maintainer.js new file mode 100644 index 00000000000000..fb515afb6f004b --- /dev/null +++ b/lib/v2/mpaypass/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/main/:type?': ['zhuan-zhu'], + '/news': ['LogicJake', 'genghis-yang'], +}; diff --git a/lib/v2/mpaypass/news.js b/lib/v2/mpaypass/news.js new file mode 100644 index 00000000000000..5dbb471c88f1b2 --- /dev/null +++ b/lib/v2/mpaypass/news.js @@ -0,0 +1,39 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const link = 'http://m.mpaypass.com.cn'; + const listData = await got(link); + const $list = cheerio.load(listData.data); + ctx.state.data = { + title: '新闻 - 移动支付网', + link, + language: 'zh-CN', + item: await Promise.all( + $list('.Newslist-li') + .map((_, el) => { + const $el = $list(el); + const $a = $el.find('.Newslist-title a'); + const href = $a.attr('href'); + const title = $a.text(); + const date = $el.find('.Newslist-time span').text(); + + return ctx.cache.tryGet(href, async () => { + const contentData = await got.get(href); + const $content = cheerio.load(contentData.data); + const description = $content('.newslist-body').html(); + + return { + title, + description, + link: href, + pubDate: timezone(parseDate(date), +8), + }; + }); + }) + .get() + ), + }; +}; diff --git a/lib/v2/mpaypass/radar.js b/lib/v2/mpaypass/radar.js new file mode 100644 index 00000000000000..65b31f511367d9 --- /dev/null +++ b/lib/v2/mpaypass/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'mpaypass.com.cn': { + _name: '移动支付网', + '.': [ + { + title: '新闻', + docs: 'https://docs.rsshub.app/new-media.html#yi-dong-zhi-fu-wang', + source: '/', + target: '/mpaypass/news', + }, + { + title: '分类', + docs: 'https://docs.rsshub.app/new-media.html#yi-dong-zhi-fu-wang', + source: ['/:type', '/'], + target: (params) => `/mpaypass/main/${params.type.replace('.html', '')}`, + }, + ], + }, +}; diff --git a/lib/v2/mpaypass/router.js b/lib/v2/mpaypass/router.js new file mode 100644 index 00000000000000..3d20601e67fb92 --- /dev/null +++ b/lib/v2/mpaypass/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/main/:type?', require('./main')); + router.get('/news', require('./news')); +};