Files
RSSHub/routes/greasyfork/scripts.js
imlonghao 09c92b363e fix axios params error (#436)
axios 中设置 headers 的参数应该是 `headers` 而不是 `header`
2018-08-08 17:32:46 +08:00

46 lines
1.4 KiB
JavaScript

const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const config = require('../../config');
module.exports = async (ctx) => {
const language = ctx.params.language === 'all' ? 'zh-CN' : ctx.params.language;
const domain = ctx.params.domain;
const filter_locale = ctx.params.language === 'all' ? 0 : 1;
const url = domain ? `by-site/${domain}` : '';
const res = await axios({
method: 'get',
url: `https://greasyfork.org/${language}/scripts/${url}`,
params: {
filter_locale: filter_locale,
sort: 'updated',
},
headers: {
'User-Agent': config.ua,
},
});
const data = res.data;
const $ = cheerio.load(data);
const list = $('.script-list').find('h2');
ctx.state.data = {
title: $('title')
.first()
.text(),
link: `https://greasyfork.org/${language}/scripts/${url}`,
description: $('meta[name=description]').attr('content'),
item:
list &&
list
.map((index, item) => {
item = $(item);
return {
title: item.find('a').text(),
description: item.find('.description').text(),
link: `https://greasyfork.org${item.find('a').attr('href')}`,
};
})
.get(),
};
};