diff --git a/docs/social-media.md b/docs/social-media.md index 0ad5d725bf..3e38c505bf 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -474,7 +474,7 @@ ## Matters - + diff --git a/lib/routes/matters/latest.js b/lib/routes/matters/latest.js index 15302006d5..6606bddad8 100644 --- a/lib/routes/matters/latest.js +++ b/lib/routes/matters/latest.js @@ -1,3 +1,4 @@ +const cheerio = require('cheerio'); const axios = require('../../utils/axios'); module.exports = async (ctx) => { @@ -16,16 +17,26 @@ module.exports = async (ctx) => { }, }); - console.log(response.data); - const items = response.data.data.viewer.recommendation.feed.edges.map(({ node }) => { - const link = `https://matters.news/@${node.author.userName}/${encodeURIComponent(node.slug)}-${node.mediaHash}`; + const items = await Promise.all( + response.data.data.viewer.recommendation.feed.edges.map(async ({ node }) => { + const link = `https://matters.news/@${node.author.userName}/${encodeURIComponent(node.slug)}-${node.mediaHash}`; + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + const res = await axios.get(link); + const $ = cheerio.load(res.data); + const article = $('.u-content').html(); + const single = { + title: node.title, + link, + description: article, + }; - return { - title: node.title, - link, - description: node.summary, - }; - }); + ctx.cache.set(link, JSON.stringify(single), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); ctx.state.data = { title: 'Matters | 最新文章',