diff --git a/lib/routes/dongqiudi/daily.js b/lib/routes/dongqiudi/daily.js index 6cd9c6bd0..a89c47946 100644 --- a/lib/routes/dongqiudi/daily.js +++ b/lib/routes/dongqiudi/daily.js @@ -1,6 +1,7 @@ const axios = require('../../utils/axios'); const cheerio = require('cheerio'); const utils = require('./utils'); +const date = require('../../utils/date'); module.exports = async (ctx) => { const response = await axios.get('https://www.dongqiudi.com/special/48'); @@ -10,7 +11,7 @@ module.exports = async (ctx) => { const host = 'https://www.dongqiudi.com'; const list = $('.detail.special ul li h3') - .slice(0, 10) + .slice(0, 5) .get(); const proList = []; @@ -21,18 +22,19 @@ module.exports = async (ctx) => { const title = $('a').text(); const itemUrl = host + $('a').attr('href'); + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + const single = { title, link: itemUrl, }; - try { - const es = axios.get(itemUrl); - proList.push(es); - return Promise.resolve(single); - } catch (err) { - console.log(`${title}: ${itemUrl} -- ${err.response.status}: ${err.response.statusText}`); - } + const es = axios.get(itemUrl); + proList.push(es); + return Promise.resolve(single); }) ); @@ -43,11 +45,19 @@ module.exports = async (ctx) => { out[i].description = utils.ProcessHref(full.find('div:nth-of-type(1)')).html(); out[i].author = full.find('span.name').text(); - out[i].pubDate = new Date(full.find('span.time').text()).toUTCString(); + out[i].pubDate = date( + full + .find('span.time') + .text() + .trim(), + 8 + ); + + ctx.cache.set(out[i].itemUrl, JSON.stringify(out[i]), 24 * 60 * 60); } ctx.state.data = { title: '懂球帝早报', link: 'http://www.dongqiudi.com/special/48', - item: out, + item: out.filter((e) => e !== undefined), }; };