From c4dd02cae7d458486d140b175da9cc0336205e01 Mon Sep 17 00:00:00 2001 From: duhd1993 Date: Sat, 2 Jan 2021 19:25:25 -0500 Subject: [PATCH 1/3] caixin: add fulltext to the article route --- lib/routes/caixin/article.js | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/routes/caixin/article.js b/lib/routes/caixin/article.js index 29fd6d70a0..fe8d617c01 100644 --- a/lib/routes/caixin/article.js +++ b/lib/routes/caixin/article.js @@ -1,4 +1,5 @@ const got = require('@/utils/got'); +const cheerio = require('cheerio'); module.exports = async (ctx) => { const response = await got({ @@ -12,15 +13,33 @@ module.exports = async (ctx) => { const data = response.data.data.list; + const items = await Promise.all( + data.map(async (item) => { + const link = item.web_url; + const summary = `

摘要:${item.summary}

`; + + const fullText = await ctx.cache.tryGet(link, async () => { + const result = await got.get(link); + + const $ = cheerio.load(result.data); + + return $('#Main_Content_Val').html(); + }); + + return { + title: item.title, + description: summary + fullText, + link: link, + pubDate: new Date(item.time * 1000), + author: item.author_name, + }; + }) + ); + ctx.state.data = { title: `财新网 - 首页`, link: `http://www.caixin.com/`, description: '财新网 - 首页', - item: data.map((item) => ({ - title: item.title, - description: `

${item.summary}

`, - link: item.web_url, - pubDate: new Date(item.time * 1000), - })), + item: items, }; }; From df5e015dd79663fece927c25c28515f1c6727a47 Mon Sep 17 00:00:00 2001 From: duhd1993 Date: Sat, 2 Jan 2021 19:52:43 -0500 Subject: [PATCH 2/3] caixin: do not display fullText when it's not article --- lib/routes/caixin/article.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/caixin/article.js b/lib/routes/caixin/article.js index fe8d617c01..bef43439cd 100644 --- a/lib/routes/caixin/article.js +++ b/lib/routes/caixin/article.js @@ -28,7 +28,7 @@ module.exports = async (ctx) => { return { title: item.title, - description: summary + fullText, + description: fullText ? summary + fullText : summary, link: link, pubDate: new Date(item.time * 1000), author: item.author_name, From e1a3f8c8698e6df2cf16db82a12d5f662f30382d Mon Sep 17 00:00:00 2001 From: duhd1993 Date: Sat, 2 Jan 2021 20:36:18 -0500 Subject: [PATCH 3/3] caixin: style of article route --- lib/routes/caixin/article.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/caixin/article.js b/lib/routes/caixin/article.js index bef43439cd..6874fe8aad 100644 --- a/lib/routes/caixin/article.js +++ b/lib/routes/caixin/article.js @@ -16,7 +16,7 @@ module.exports = async (ctx) => { const items = await Promise.all( data.map(async (item) => { const link = item.web_url; - const summary = `

摘要:${item.summary}

`; + const summary = `

${item.summary}

`; const fullText = await ctx.cache.tryGet(link, async () => { const result = await got.get(link);