diff --git a/lib/routes/guanchazhe/topic.js b/lib/routes/guanchazhe/topic.js index bc9208a04f..539c3583d3 100644 --- a/lib/routes/guanchazhe/topic.js +++ b/lib/routes/guanchazhe/topic.js @@ -1,5 +1,6 @@ const cheerio = require('cheerio'); const axios = require('../../utils/axios'); +const date = require('../../utils/date'); const url = require('url'); const host = 'https://user.guancha.cn'; @@ -21,9 +22,15 @@ module.exports = async (ctx) => { list.map(async (itemUrl) => { // 将相对链接替换为绝对链接 const absoluteUrl = url.resolve(host, itemUrl); + const cache = await ctx.cache.get(absoluteUrl); + // 判断缓存 + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } const res = await axios.get(absoluteUrl); const $ = cheerio.load(res.data); + const dateStr = $('.user-main .time1').text(); const item = { title: $('.article-content h1').text(), author: $('.user-main h4') @@ -32,12 +39,9 @@ module.exports = async (ctx) => { .text(), link: absoluteUrl, description: $('.article-txt-content').html(), - pubDate: $('.user-main .time1').text(), + // 格式化日期 + pubDate: date(dateStr), }; - const cache = await ctx.cache.get(absoluteUrl); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } ctx.cache.set(absoluteUrl, JSON.stringify(item), 24 * 60 * 60); return Promise.resolve(item);