const got = require('@/utils/got'); const cheerio = require('cheerio'); module.exports = async (ctx) => { const since = ctx.params.since; const language = ctx.params.language || ''; const url = `https://github.com/trending/${encodeURIComponent(language)}?since=${since}`; const response = await got({ method: 'get', url: url, headers: { Referer: url, }, }); const data = response.data; const $ = cheerio.load(data); const list = $('article'); ctx.state.data = { title: $('title').text(), link: url, item: list && list .map((index, item) => { item = $(item); return { title: item.find('h1').text(), description: `${item.find('.pr-4').text()}

Language: ${item.find('span[itemprop="programmingLanguage"]').text() || 'unknown'}
Star: ${item.find('.muted-link').eq(0).text()}
Fork: ${item.find('.muted-link').eq(1).text()}`, link: `https://github.com${item.find('h1 a').attr('href')}`, }; }) .get(), }; };