const got = require('@/utils/got'); const cheerio = require('cheerio'); const timezone = require('@/utils/timezone'); const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const rootUrl = 'https://allrecode.com'; const currentUrl = `${rootUrl}/news`; const response = await got({ method: 'get', url: currentUrl, }); const $ = cheerio.load(response.data); const items = $('.news-trigger') .toArray() .map((item) => { item = $(item); return { title: item.text(), link: item.attr('href'), pubDate: timezone(parseDate(item.parent().prev().text(), 'HH:mm'), +8), description: item.parent().next().html(), }; }); ctx.state.data = { title: $('title').text(), link: currentUrl, item: items, }; };