Files
RSSHub/lib/routes/luogu/contest.js
Sukka d82847f541 style/chore(eslint): enforce new rules (#8040)
* style: prefer object shorthand syntax
* refactor: prefer Array#map over Array#forEach
* style: prefer arrow callback
* chore(eslint): update rules
* style: auto fix by eslint
2021-08-17 22:23:23 +08:00

29 lines
837 B
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const resolve_url = require('url').resolve;
module.exports = async (ctx) => {
const link = 'https://www.luogu.com.cn/';
const response = await got.get(link);
const $ = cheerio.load(response.data);
const title = '洛谷近期比赛';
const out = $('.am-panel-hd ')
.slice(0, 10)
.map(function () {
const info = {
title: $(this).find('a').text() || $(this).text(),
description: $(this).html() + $(this).parent().find('.am-panel-bd').html(),
link: resolve_url('https://www.luogu.com.cn', $(this).find('a').attr('href')),
};
return info;
})
.get();
ctx.state.data = {
title,
link,
item: out,
};
};