From decbb70e4d3a8ea8b80d13c6900efece62518ba9 Mon Sep 17 00:00:00 2001 From: Laam Pui Date: Thu, 24 Dec 2020 01:55:14 +0800 Subject: [PATCH] fix: outdated route /hex-rays/news (#6508) --- lib/routes/hex-rays/index.js | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/lib/routes/hex-rays/index.js b/lib/routes/hex-rays/index.js index 9a5a81caa..35505a69b 100644 --- a/lib/routes/hex-rays/index.js +++ b/lib/routes/hex-rays/index.js @@ -2,30 +2,23 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); module.exports = async (ctx) => { - let host = 'https://www.hex-rays.com'; - - host = `${host}/news.shtml`; - - const response = await got.get(host); - + const link = 'https://www.hex-rays.com/blog/'; + const response = await got.get(link); const $ = cheerio.load(response.data); - const list = $('tr[bgcolor]'); + const item = $('.post-list-container') + .map((index, 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(), + })) + .get(); ctx.state.data = { - title: 'Hex-Rays News', - link: host, - item: - list && - list - .map((index, item) => { - item = $(item); - return { - title: item.find('td:nth-child(1)').text() + ' ' + item.find('td:nth-child(2)').text(), - link: item.find('td:nth-child(2) > a').attr('href'), - }; - }) - .get(), + title: 'Hex-Rays Blog', + link, + item, }; };