Skip to content

Commit

Permalink
refactor(route): migrate to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL committed Dec 20, 2021
1 parent ff0ccf4 commit 57ffb21
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 31 deletions.
4 changes: 2 additions & 2 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
29 changes: 0 additions & 29 deletions lib/routes/hex-rays/index.js

This file was deleted.

47 changes: 47 additions & 0 deletions lib/v2/hex-rays/index.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
3 changes: 3 additions & 0 deletions lib/v2/hex-rays/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/news': ['hellodword ', 'TonyRL'],
};
13 changes: 13 additions & 0 deletions lib/v2/hex-rays/radar.js
Original file line number Diff line number Diff line change
@@ -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',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/hex-rays/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/news', require('./index'));
};

0 comments on commit 57ffb21

Please sign in to comment.