Files
RSSHub/lib/routes/andyt/index.js
T
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

37 lines
1.1 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const baseUrl = 'https://andyt.cn/forum.php?mod=guide&view=';
const host = 'https://andyt.cn/';
const viewProps = {
newthread: '最新发表',
hot: '最新热门',
digest: '最新精华',
new: '最新回复',
};
module.exports = async (ctx) => {
const view = ctx.params.view || 'newthread';
const url = baseUrl + view;
const response = await got({
method: 'get',
url,
});
const $ = cheerio.load(response.data);
ctx.state.data = {
title: `${viewProps[view]} - 书友社区`,
link: url,
description: `${viewProps[view]} - 书友社区`,
item: $('.bm_c')
.find('tbody')
.map((index, item) => ({
title: `【` + $(item).find('td.by a').eq(0).text() + `】` + $(item).find('a.xst').text(),
description: '',
author: $(item).find('cite').text().trim(),
link: host + $(item).find('a').eq(0).attr('href'),
}))
.get(),
};
};