From ed5c6fff48c26b1e9bba4060450ffa1e799c1ebe Mon Sep 17 00:00:00 2001 From: SunBK201 Date: Fri, 19 Jan 2024 17:00:33 +0800 Subject: [PATCH] feat(secrss): full text support (#14284) * feat(secrss): full text support * fix(secrss): pubDate author category --- lib/v2/secrss/author.js | 25 ++++++++++++++++++------- lib/v2/secrss/category.js | 27 +++++++++++++++++++-------- lib/v2/secrss/maintainer.js | 4 ++-- website/docs/routes/programming.mdx | 4 ++-- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/lib/v2/secrss/author.js b/lib/v2/secrss/author.js index 02667778e..ee221ff0c 100644 --- a/lib/v2/secrss/author.js +++ b/lib/v2/secrss/author.js @@ -1,5 +1,6 @@ const got = require('@/utils/got'); const { parseDate } = require('@/utils/parse-date'); +const cheerio = require('cheerio'); module.exports = async (ctx) => { const api = 'https://www.secrss.com/api/articles/group?author='; @@ -8,13 +9,23 @@ module.exports = async (ctx) => { const res = await got(`${api}${author}`); const dataArray = res.data.data.list; - const items = dataArray.map((item) => ({ - title: item.title, - description: item.summary, - pubDate: parseDate(item.original_timestamp, 'X'), - link: `${host}${item.url}`, - category: item.tag, - })); + const items = await Promise.all( + dataArray.map((item) => { + const itemUrl = `${host}${item.url}`; + return ctx.cache.tryGet(itemUrl, async () => { + const result = await got(itemUrl); + const $ = cheerio.load(result.data); + const description = $('.article-body').html().trim(); + return { + title: item.title, + link: itemUrl, + pubDate: parseDate(item.original_timestamp, 'X'), + description, + category: item.tag, + }; + }); + }) + ); ctx.state.data = { title: `安全内参-${author}`, diff --git a/lib/v2/secrss/category.js b/lib/v2/secrss/category.js index b2ded630d..212c43268 100644 --- a/lib/v2/secrss/category.js +++ b/lib/v2/secrss/category.js @@ -1,6 +1,7 @@ const got = require('@/utils/got'); const { parseDate } = require('@/utils/parse-date'); const timezone = require('@/utils/timezone'); +const cheerio = require('cheerio'); module.exports = async (ctx) => { const api = 'https://www.secrss.com/api/articles?tag='; @@ -9,14 +10,24 @@ module.exports = async (ctx) => { const res = await got(`${api}${category}`); const dataArray = res.data.data; - const items = dataArray.map((item) => ({ - title: item.title, - description: item.summary, - pubDate: timezone(parseDate(item.published_at), +8), - link: `${host}/articles/${item.id}`, - author: item.source_author, - category: item.tags.map((t) => t.title), - })); + const items = await Promise.all( + dataArray.map((item) => { + const itemUrl = `${host}/articles/${item.id}`; + return ctx.cache.tryGet(itemUrl, async () => { + const result = await got(itemUrl); + const $ = cheerio.load(result.data); + const description = $('.article-body').html().trim(); + return { + title: item.title, + link: itemUrl, + pubDate: timezone(parseDate(item.published_at), 8), + description, + author: item.source_author, + category: item.tags.map((t) => t.title), + }; + }); + }) + ); ctx.state.data = { title: `安全内参-${category}`, diff --git a/lib/v2/secrss/maintainer.js b/lib/v2/secrss/maintainer.js index d7a31b968..4d0bb90ed 100644 --- a/lib/v2/secrss/maintainer.js +++ b/lib/v2/secrss/maintainer.js @@ -1,4 +1,4 @@ module.exports = { - '/author/:author': ['XinRoom'], - '/category/:category?': ['XinRoom'], + '/author/:author': ['XinRoom', 'SunBK201'], + '/category/:category?': ['XinRoom', 'SunBK201'], }; diff --git a/website/docs/routes/programming.mdx b/website/docs/routes/programming.mdx index c4d14219b..1f357b7e2 100644 --- a/website/docs/routes/programming.mdx +++ b/website/docs/routes/programming.mdx @@ -809,11 +809,11 @@ Stay up to date on the latest React news, tutorials, resources, and more. Delive ### 分类 {#an-quan-nei-can-fen-lei} - + ### 作者 {#an-quan-nei-can-zuo-zhe} - + ## 北京智源人工智能研究院 {#bei-jing-zhi-yuan-ren-gong-zhi-neng-yan-jiu-yuan}