fix: latest comments from lowendtalk discussions (#6437)

This commit is contained in:
Ethan Shen 2020-12-14 19:50:48 +08:00 committed by GitHub
parent 14fc4af1ef
commit 0aeee4fa99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 3 deletions

View File

@ -4,12 +4,19 @@ const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://www.lowendtalk.com';
const currentUrl = `${rootUrl}/discussion/${ctx.params.id}`;
const response = await got({
let response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
let $ = cheerio.load(response.data);
response = await got({
method: 'get',
url: $('.LastPage').attr('href'),
});
$ = cheerio.load(response.data);
const items = $('.userContent')
.map((_, item) => {
@ -29,7 +36,7 @@ module.exports = async (ctx) => {
.get();
ctx.state.data = {
title: $('title').text(),
title: $('h1').eq(0).text(),
link: currentUrl,
item: items,
};