fix: outdated route /hex-rays/news (#6508)

This commit is contained in:
Laam Pui 2020-12-24 01:55:14 +08:00 committed by GitHub
parent abcf932555
commit decbb70e4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 20 deletions

View File

@ -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,
};
};