diff --git a/docs/new-media.md b/docs/new-media.md index c879a7fcdf..6430d5b514 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1120,17 +1120,13 @@ Supported sub-sites: ## ZAKER -### source +### 分类 - - -### channel - - + ### 精读 - + ## 爱范儿 ifanr diff --git a/lib/router.js b/lib/router.js index a005f883c9..939ff00ada 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1606,9 +1606,9 @@ router.get('/checkee/:dispdate', lazyloadRouteHandler('./routes/checkee/index')) // 艾瑞 router.get('/iresearch/report', lazyloadRouteHandler('./routes/iresearch/report')); -// ZAKER -router.get('/zaker/:type/:id', lazyloadRouteHandler('./routes/zaker/source')); -router.get('/zaker/focusread', lazyloadRouteHandler('./routes/zaker/focusread')); +// ZAKER migrated to v2 +// router.get('/zaker/:type/:id', lazyloadRouteHandler('./routes/zaker/source')); +// router.get('/zaker/focusread', lazyloadRouteHandler('./routes/zaker/focusread')); // Matters router.get('/matters/latest/:type?', lazyloadRouteHandler('./routes/matters/latest')); diff --git a/lib/routes/zaker/focusread.js b/lib/routes/zaker/focusread.js deleted file mode 100644 index b499ca50d7..0000000000 --- a/lib/routes/zaker/focusread.js +++ /dev/null @@ -1,65 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseRelativeDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); - -module.exports = async (ctx) => { - const link = `http://www.myzaker.com/?pos=selected_article`; - - const response = await got.get(link); - const $ = cheerio.load(response.data); - const title = $('.main-title').text(); - - const list = $('div.content-block') - .slice(0, 10) - .map(function () { - const info = { - title: $(this).find('.article-title').text(), - link: $(this).find('.article-wrap > a').attr('href'), - }; - return info; - }) - .get(); - - const out = await Promise.all( - list.map(async (info) => { - const title = info.title; - const itemUrl = 'http:' + info.link; - - const cache = await ctx.cache.get(itemUrl); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - - const response = await got({ - url: itemUrl, - method: 'get', - headers: { - Referer: link, - }, - }); - - const $ = cheerio.load(response.data); - - const description = $('div.article_content div').html() || '原文已被删除'; - - const date = $('span.time').text(); - - const single = { - title, - link: itemUrl, - description, - pubDate: timezone(parseRelativeDate(date), +8), - }; - ctx.cache.set(itemUrl, JSON.stringify(single)); - return Promise.resolve(single); - }) - ); - const outfilter = out.filter((t) => t.description !== '原文已被删除'); - - ctx.state.data = { - title: `${title}-ZAKER精读新闻`, - link, - item: outfilter, - }; -}; diff --git a/lib/routes/zaker/source.js b/lib/routes/zaker/source.js deleted file mode 100644 index bb40323761..0000000000 --- a/lib/routes/zaker/source.js +++ /dev/null @@ -1,66 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseRelativeDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); - -module.exports = async (ctx) => { - const type = ctx.params.type || 'source'; - const id = ctx.params.id; - const link = `http://www.myzaker.com/${type}/${id}`; - - const response = await got.get(link); - const $ = cheerio.load(response.data); - const title = $('.main-title').text(); - - const list = $('div.content-block') - .slice(0, 10) - .map(function () { - const info = { - title: $(this).find('.article-title').text(), - link: $(this).find('.article-wrap > a').attr('href'), - }; - return info; - }) - .get(); - - const out = await Promise.all( - list.map(async (info) => { - const title = info.title; - const itemUrl = 'http:' + info.link; - - const cache = await ctx.cache.get(itemUrl); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - - const response = await got({ - url: itemUrl, - method: 'get', - headers: { - Referer: link, - }, - }); - - const $ = cheerio.load(response.data); - - const description = $('div.article_content div').html() || '原文已被删除'; - - const date = $('span.time').text(); - - const single = { - title, - link: itemUrl, - description, - pubDate: timezone(parseRelativeDate(date), +8), - }; - ctx.cache.set(itemUrl, JSON.stringify(single)); - return Promise.resolve(single); - }) - ); - - ctx.state.data = { - title: `${title}-ZAKER新闻`, - link, - item: out, - }; -}; diff --git a/lib/v2/zaker/index.js b/lib/v2/zaker/index.js new file mode 100644 index 0000000000..5fea55574b --- /dev/null +++ b/lib/v2/zaker/index.js @@ -0,0 +1,65 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseRelativeDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const type = ctx.params.type ?? 'channel'; + const id = ctx.params.id ?? 1; + const rootUrl = 'http://www.myzaker.com'; + const link = type === 'focusread' ? `${rootUrl}/?pos=selected_article` : `${rootUrl}/${type}/${id}`; + + const response = await got({ + url: link, + headers: { + Referer: rootUrl, + }, + }); + const $ = cheerio.load(response.data); + const feedTitle = $('head title').text(); + + let items = $('div.content-block') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.find('.article-title').text(), + link: 'http:' + item.find('.article-wrap > a').attr('href').replace('http://', ''), + }; + }) + .get(); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const response = await got({ + url: item.link, + headers: { + Referer: link, + }, + }); + + const $ = cheerio.load(response.data); + + item.description = $('div.article_content div').html() ?? '原文已被删除'; + item.author = $('a.article-auther.line').text(); + item.category = $('.lebel-list') + .find('a') + .toArray() + .map((item) => $(item).text()); + const date = $('span.time').text() ?? undefined; + if (date) { + item.pubDate = timezone(parseRelativeDate(date), +8); + } + + return item; + }) + ) + ); + + ctx.state.data = { + title: type === 'focusread' ? 'ZAKER 精读新闻' : feedTitle, + link, + item: items.filter((t) => t.description !== '原文已被删除'), + }; +}; diff --git a/lib/v2/zaker/maintainer.js b/lib/v2/zaker/maintainer.js new file mode 100644 index 0000000000..61b600e33f --- /dev/null +++ b/lib/v2/zaker/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:type/:id?': ['LogicJake', 'kt286', 'AlexdanerZe', 'TonyRL'], +}; diff --git a/lib/v2/zaker/radar.js b/lib/v2/zaker/radar.js new file mode 100644 index 0000000000..6d89839d59 --- /dev/null +++ b/lib/v2/zaker/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'myzaker.com': { + _name: 'ZAKER', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/new-media.html#zaker', + source: ['/:type/:id'], + target: '/zaker/:type/:id', + }, + { + title: '精读', + docs: 'https://docs.rsshub.app/new-media.html#zaker', + source: ['/'], + target: '/zaker/focusread', + }, + ], + }, +}; diff --git a/lib/v2/zaker/router.js b/lib/v2/zaker/router.js new file mode 100644 index 0000000000..89c0d87528 --- /dev/null +++ b/lib/v2/zaker/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:type/:id?', require('./index')); +};