From 1232a08e1caf070a2790a752dfbe4510a0e4713f Mon Sep 17 00:00:00 2001 From: TonyRL Date: Thu, 16 Sep 2021 12:20:21 +0000 Subject: [PATCH 1/2] fix(route): hex-rays news pubDate and author --- lib/routes/hex-rays/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/routes/hex-rays/index.js b/lib/routes/hex-rays/index.js index 35505a69b87117..851b25da3b95e1 100644 --- a/lib/routes/hex-rays/index.js +++ b/lib/routes/hex-rays/index.js @@ -1,5 +1,6 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const link = 'https://www.hex-rays.com/blog/'; @@ -7,11 +8,11 @@ module.exports = async (ctx) => { const $ = cheerio.load(response.data); const item = $('.post-list-container') - .map((index, ele) => ({ + .map((_, ele) => ({ title: $('h3 > a', ele).text(), link: $('h3 > a', ele).attr('href'), - pubDate: new Date($('.post-meta:nth-of-type(1)', ele).text().trim().replace('Posted on:', '')), - author: $('.post-meta:nth-of-type(2)', ele).text().trim(), + pubDate: parseDate($('.post-meta:nth-of-type(1)', ele).first().text().trim().replace('Posted on:', '')), + author: $('.post-meta:nth-of-type(2)', ele).first().text().trim().replace('By:', ''), })) .get(); From 57ffb2122b78c1b7dde67d3f6374e46ff5df7415 Mon Sep 17 00:00:00 2001 From: TonyRL Date: Mon, 20 Dec 2021 22:17:19 +0800 Subject: [PATCH 2/2] refactor(route): migrate to v2 --- lib/router.js | 4 +-- lib/routes/hex-rays/index.js | 29 --------------------- lib/v2/hex-rays/index.js | 47 +++++++++++++++++++++++++++++++++++ lib/v2/hex-rays/maintainer.js | 3 +++ lib/v2/hex-rays/radar.js | 13 ++++++++++ lib/v2/hex-rays/router.js | 3 +++ 6 files changed, 68 insertions(+), 31 deletions(-) delete mode 100644 lib/routes/hex-rays/index.js create mode 100644 lib/v2/hex-rays/index.js create mode 100644 lib/v2/hex-rays/maintainer.js create mode 100644 lib/v2/hex-rays/radar.js create mode 100644 lib/v2/hex-rays/router.js diff --git a/lib/router.js b/lib/router.js index daa24dde37ca31..fc3f58d5687220 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2513,8 +2513,8 @@ router.get('/galaxylab', lazyloadRouteHandler('./routes/galaxylab/index')); // NOSEC 安全讯息平台 router.get('/nosec/:keykind?', lazyloadRouteHandler('./routes/nosec/index')); -// Hex-Rays News -router.get('/hex-rays/news', lazyloadRouteHandler('./routes/hex-rays/index')); +// Hex-Rays News migrated to v2 +// router.get('/hex-rays/news', lazyloadRouteHandler('./routes/hex-rays/index')); // 新趣集 router.get('/xinquji/today', lazyloadRouteHandler('./routes/xinquji/today')); diff --git a/lib/routes/hex-rays/index.js b/lib/routes/hex-rays/index.js deleted file mode 100644 index 851b25da3b95e1..00000000000000 --- a/lib/routes/hex-rays/index.js +++ /dev/null @@ -1,29 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); - -module.exports = async (ctx) => { - const link = 'https://www.hex-rays.com/blog/'; - const response = await got.get(link); - const $ = cheerio.load(response.data); - - const item = $('.post-list-container') - .map((_, ele) => ({ - title: $('h3 > a', ele).text(), - link: $('h3 > a', ele).attr('href'), - pubDate: parseDate($('.post-meta:nth-of-type(1)', ele).first().text().trim().replace('Posted on:', '')), - author: $('.post-meta:nth-of-type(2)', ele).first().text().trim().replace('By:', ''), - })) - .get(); - - ctx.state.data = { - title: 'Hex-Rays Blog', - link, - item, - }; -}; - -// 虽然能够用插件探测到疑似feed,但是实际请求会发现需要登录 -// https://forum.hex-rays.com/app.php/feed/news - -// 正文部分比较...乱且意义不大,所以没有正文 diff --git a/lib/v2/hex-rays/index.js b/lib/v2/hex-rays/index.js new file mode 100644 index 00000000000000..4d162daf13fa5c --- /dev/null +++ b/lib/v2/hex-rays/index.js @@ -0,0 +1,47 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const link = 'https://www.hex-rays.com/blog/'; + const response = await got.get(link); + const $ = cheerio.load(response.data); + + const list = $('.post-list-container') + .map((_, ele) => ({ + title: $('h3 > a', ele).text(), + link: $('h3 > a', ele).attr('href'), + pubDate: parseDate($('.post-meta:nth-of-type(1)', ele).first().text().trim().replace('Posted on:', '')), + author: $('.post-meta:nth-of-type(2)', ele).first().text().replace('By:', '').trim(), + })) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got.get(item.link); + const content = cheerio.load(detailResponse.data); + + item.category = ( + content('.category-link') + .toArray() + .map((e) => $(e).text()) + + ',' + + content('.tag-link') + .toArray() + .map((e) => $(e).text()) + ).split(','); + + item.description = content('.post-content').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: 'Hex-Rays Blog', + link, + item: items, + }; +}; diff --git a/lib/v2/hex-rays/maintainer.js b/lib/v2/hex-rays/maintainer.js new file mode 100644 index 00000000000000..dc0cb2c7d016a3 --- /dev/null +++ b/lib/v2/hex-rays/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news': ['hellodword ', 'TonyRL'], +}; diff --git a/lib/v2/hex-rays/radar.js b/lib/v2/hex-rays/radar.js new file mode 100644 index 00000000000000..930517e6180296 --- /dev/null +++ b/lib/v2/hex-rays/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'hex-rays.com': { + _name: 'Hex-Rays', + '.': [ + { + title: 'Hex-Rays News', + docs: 'https://docs.rsshub.app/programming.html#hex-rays', + source: ['/', '/blog'], + target: '/hex-rays/news', + }, + ], + }, +}; diff --git a/lib/v2/hex-rays/router.js b/lib/v2/hex-rays/router.js new file mode 100644 index 00000000000000..8c93c0dba8d75e --- /dev/null +++ b/lib/v2/hex-rays/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/news', require('./index')); +};