Files
RSSHub/lib/routes/luogu/daily.js
2019-06-03 18:03:05 +08:00

35 lines
917 B
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id || 92685;
const link = `https://www.luogu.org/discuss/show/${id}`;
const response = await got.get(link);
const $ = cheerio.load(response.data);
const title = $('#app-body-new div h1').text();
const out = $('div.am-comment-main > div > p')
.slice(0, 10)
.map(function() {
const info = {
title:
$(this)
.find('strong')
.text() || $(this).text(),
description: $(this).html(),
link: $(this)
.find('a')
.attr('href'),
};
return info;
})
.get();
ctx.state.data = {
title: title,
link: link,
item: out,
};
};