diff --git a/lib/router.js b/lib/router.js index 3ad7664193..792dadbf1f 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2195,9 +2195,9 @@ router.get('/wineyun/:category', lazyloadRouteHandler('./routes/wineyun')); router.get('/xiaohongshu/user/:user_id/:category', lazyloadRouteHandler('./routes/xiaohongshu/user')); router.get('/xiaohongshu/board/:board_id', lazyloadRouteHandler('./routes/xiaohongshu/board')); -// 每经网 -router.get('/nbd/daily', lazyloadRouteHandler('./routes/nbd/article')); -router.get('/nbd/:id?', lazyloadRouteHandler('./routes/nbd/index')); +// 每经网 migrated to v2 +// router.get('/nbd/daily', lazyloadRouteHandler('./routes/nbd/article')); +// router.get('/nbd/:id?', lazyloadRouteHandler('./routes/nbd/index')); // 快知 router.get('/kzfeed/topic/:id', lazyloadRouteHandler('./routes/kzfeed/topic')); diff --git a/lib/routes/nbd/article.js b/lib/routes/nbd/article.js deleted file mode 100644 index 58d9c7835f..0000000000 --- a/lib/routes/nbd/article.js +++ /dev/null @@ -1,60 +0,0 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const url = 'http://www.nbd.com.cn/columns/332'; - const response = await got({ - method: 'get', - url, - headers: { - Referer: 'http://www.nbd.com.cn', - }, - }); - - const $ = cheerio.load(response.data); - const $list = $('li.u-news-title').slice(0, 15).get(); - const description = $('head title').text().trim(); - - const resultItem = await Promise.all( - $list.map(async (item) => { - const title = $(item).find('a').text().trim(); - const pubDate = $(item).find('span').text().trim(); - const itemUrl = $(item).find('a').attr('href'); - - const single = { - title, - link: itemUrl, - pubDate, - description: '', - }; - - const cache = await ctx.cache.get(itemUrl); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - - const detail = await got({ - method: 'get', - url: itemUrl, - headers: { - Referer: 'http://www.nbd.com.cn', - }, - }); - - { - const $ = cheerio.load(detail.data); - single.description = $('div.g-article').html(); - } - - ctx.cache.set(itemUrl, JSON.stringify(single)); - return Promise.resolve(single); - }) - ); - - ctx.state.data = { - title: '重磅原创-每经网', - link: url, - item: resultItem, - description, - }; -}; diff --git a/lib/v2/nbd/article.js b/lib/v2/nbd/article.js new file mode 100644 index 0000000000..0cba9f757d --- /dev/null +++ b/lib/v2/nbd/article.js @@ -0,0 +1,50 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); +module.exports = async (ctx) => { + const url = 'https://www.nbd.com.cn/columns/332'; + const response = await got({ + method: 'get', + url, + headers: { + Referer: 'https://www.nbd.com.cn', + }, + }); + + const $ = cheerio.load(response.data); + const $list = $('li.u-news-title').slice(0, 15).get(); + const description = $('head title').text().trim(); + + const resultItem = await Promise.all( + $list.map(async (item) => { + const title = $(item).find('a').text().trim(); + const itemUrl = 'https:' + $(item).find('a').attr('href'); + + const single = await ctx.cache.tryGet(itemUrl, async () => { + const detail = await got({ + method: 'get', + url: itemUrl, + headers: { + Referer: 'https://www.nbd.com.cn', + }, + }); + const $ = cheerio.load(detail.data); + return { + title, + link: itemUrl, + pubDate: timezone(parseDate(detail.data.match(/"pubDate": "(.*)"/)[1]), +8), + description: $('div.g-article').html(), + }; + }); + return single; + }) + ); + + ctx.state.data = { + title: '重磅原创-每经网', + link: url, + item: resultItem, + description, + }; +}; diff --git a/lib/routes/nbd/index.js b/lib/v2/nbd/index.js similarity index 76% rename from lib/routes/nbd/index.js rename to lib/v2/nbd/index.js index 25e92c99fc..1f843f439f 100644 --- a/lib/routes/nbd/index.js +++ b/lib/v2/nbd/index.js @@ -1,11 +1,14 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { - const id = ctx.params.id || '3'; + const id = ctx.params.id ?? '3'; - const rootUrl = 'http://www.nbd.com.cn'; + const rootUrl = 'https://www.nbd.com.cn'; const currentUrl = `${rootUrl}/columns/${id}`; + const response = await got({ method: 'get', url: currentUrl, @@ -14,12 +17,12 @@ module.exports = async (ctx) => { const $ = cheerio.load(response.data); const list = $('.u-news-title a') - .slice(0, 10) .map((_, item) => { item = $(item); + return { title: item.text(), - link: item.attr('href'), + link: 'https:' + item.attr('href'), }; }) .get(); @@ -34,7 +37,7 @@ module.exports = async (ctx) => { const content = cheerio.load(detailResponse.data); item.description = content('.g-articl-text').html(); - item.pubDate = new Date(detailResponse.data.match(/"pubDate": "(.*)"/)[1]).toUTCString(); + item.pubDate = timezone(parseDate(detailResponse.data.match(/"pubDate": "(.*)"/)[1]), +8); return item; }) diff --git a/lib/v2/nbd/maintainer.js b/lib/v2/nbd/maintainer.js new file mode 100644 index 0000000000..3fe5eb51ac --- /dev/null +++ b/lib/v2/nbd/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/daily': ['MeXunco'], + '/:id?': ['nczitzk'], +}; diff --git a/lib/v2/nbd/radar.js b/lib/v2/nbd/radar.js new file mode 100644 index 0000000000..5d463cd0d5 --- /dev/null +++ b/lib/v2/nbd/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'nbd.com.cn': { + _name: '每经网', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/finance.html#mei-jing-wang', + source: '/', + targer: '/nbd', + }, + { + title: '重磅原创', + docs: 'https://docs.rsshub.app/finance.html#mei-jing-wang', + source: '/', + targer: '/nbd/daily', + }, + ], + }, +}; diff --git a/lib/v2/nbd/router.js b/lib/v2/nbd/router.js new file mode 100644 index 0000000000..3e38f7de99 --- /dev/null +++ b/lib/v2/nbd/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/daily', require('./article')); + router.get('/:id?', require('./index')); +};