From a01c645757e471ef4fdb0353cf3dc65fcd076148 Mon Sep 17 00:00:00 2001 From: changren-wcr <105254603+changren-wcr@users.noreply.github.com> Date: Sat, 30 Dec 2023 23:13:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E4=B8=89=E8=81=94=E7=94=9F?= =?UTF-8?q?=E6=B4=BB=E5=91=A8=E5=88=8A=20(#14127)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): 三联生活周刊 * fix: namespace and data acquirement * fix: get article list by api * Update lib/v2/lifeweek/channel.js Co-authored-by: Tony * Update lib/v2/lifeweek/channel.js Co-authored-by: Tony * Update lib/v2/lifeweek/tag.js Co-authored-by: Tony * fix: rss url * refactor: getRssItem function * Update lib/v2/lifeweek/utils.js --------- Co-authored-by: Changren Wang --- lib/v2/lifeweek/channel.js | 25 +++++++++++++++++++++++ lib/v2/lifeweek/maintainer.js | 4 ++++ lib/v2/lifeweek/radar.js | 19 +++++++++++++++++ lib/v2/lifeweek/router.js | 4 ++++ lib/v2/lifeweek/tag.js | 24 ++++++++++++++++++++++ lib/v2/lifeweek/utils.js | 18 ++++++++++++++++ website/docs/routes/traditional-media.mdx | 22 ++++++++++++++++++++ 7 files changed, 116 insertions(+) create mode 100644 lib/v2/lifeweek/channel.js create mode 100644 lib/v2/lifeweek/maintainer.js create mode 100644 lib/v2/lifeweek/radar.js create mode 100644 lib/v2/lifeweek/router.js create mode 100644 lib/v2/lifeweek/tag.js create mode 100644 lib/v2/lifeweek/utils.js diff --git a/lib/v2/lifeweek/channel.js b/lib/v2/lifeweek/channel.js new file mode 100644 index 000000000..8ae9168e2 --- /dev/null +++ b/lib/v2/lifeweek/channel.js @@ -0,0 +1,25 @@ +const got = require('@/utils/got'); +const getRssItem = require('./utils'); + +const rootApiUrl = 'https://www.lifeweek.com.cn/api/userWebFollow/getFollowTagContentList?type=3&sort=2&tagId'; +const rootUrl = 'https://www.lifeweek.com.cn/column'; +const articleRootUrl = 'https://www.lifeweek.com.cn/article'; + +module.exports = async (ctx) => { + const channel = ctx.params.id; + const url = `${rootApiUrl}=${channel}`; + const { data } = await got(url); + const result = data.model.articleResponseList; + const items = await Promise.all( + result.map((item) => { + const articleLink = `${articleRootUrl}/${item.id}`; + return ctx.cache.tryGet(articleLink, () => getRssItem(item, articleLink)); + }) + ); + + ctx.state.data = { + title: data.model.tagName, + link: `${rootUrl}/${channel}`, + item: items, + }; +}; diff --git a/lib/v2/lifeweek/maintainer.js b/lib/v2/lifeweek/maintainer.js new file mode 100644 index 000000000..b9dca3363 --- /dev/null +++ b/lib/v2/lifeweek/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/channel/:channel': ['changren-wcr'], + '/tag/:tag': ['changren-wcr'], +}; diff --git a/lib/v2/lifeweek/radar.js b/lib/v2/lifeweek/radar.js new file mode 100644 index 000000000..80eeecd19 --- /dev/null +++ b/lib/v2/lifeweek/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'lifeweek.com.cn': { + _name: '三联生活周刊', + '.': [ + { + title: '栏目', + docs: 'https://docs.rsshub.app/routes/traditional-media#san-lian-sheng-huo-zhou-kan', + source: ['/column/:channel'], + target: '/lifeweek/channel/:channel', + }, + { + title: '标签', + docs: 'https://docs.rsshub.app/routes/traditional-media#san-lian-sheng-huo-zhou-kan', + source: ['/articleList/:tag'], + target: '/lifeweek/tag/:tag', + }, + ], + }, +}; diff --git a/lib/v2/lifeweek/router.js b/lib/v2/lifeweek/router.js new file mode 100644 index 000000000..556194740 --- /dev/null +++ b/lib/v2/lifeweek/router.js @@ -0,0 +1,4 @@ +module.exports = function (router) { + router.get('/channel/:id', require('./channel')); + router.get('/tag/:id', require('./tag')); +}; diff --git a/lib/v2/lifeweek/tag.js b/lib/v2/lifeweek/tag.js new file mode 100644 index 000000000..51a20bddd --- /dev/null +++ b/lib/v2/lifeweek/tag.js @@ -0,0 +1,24 @@ +const got = require('@/utils/got'); +const getRssItem = require('./utils'); +const rootApiUrl = 'https://www.lifeweek.com.cn/api/userWebFollow/getFollowTagContentList?type=4&sort=2&tagId'; +const rootUrl = 'https://www.lifeweek.com.cn/articleList'; +const articleRootUrl = 'https://www.lifeweek.com.cn/article'; + +module.exports = async (ctx) => { + const tag = ctx.params.id; + const url = `${rootApiUrl}=${tag}`; + const { data } = await got(url); + const result = data.model.articleResponseList; + const items = await Promise.all( + result.map((item) => { + const articleLink = `${articleRootUrl}/${item.id}`; + return ctx.cache.tryGet(articleLink, () => getRssItem(item, articleLink)); + }) + ); + + ctx.state.data = { + title: data.model.tagName, + link: `${rootUrl}/${tag}`, + item: items, + }; +}; diff --git a/lib/v2/lifeweek/utils.js b/lib/v2/lifeweek/utils.js new file mode 100644 index 000000000..67b29ae7b --- /dev/null +++ b/lib/v2/lifeweek/utils.js @@ -0,0 +1,18 @@ +const got = require('@/utils/got'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); +const articleApiRootUrl = 'https://www.lifeweek.com.cn/api/article'; + +async function getRssItem(item, articleLink) { + const articleApiLink = `${articleApiRootUrl}/${item.id}`; + const { data } = await got(articleApiLink); + const time = timezone(parseDate(item.pubTime), +8); + return { + title: item.title, + description: data.model.content, + link: articleLink, + pubDate: time, + }; +} + +module.exports = getRssItem; diff --git a/website/docs/routes/traditional-media.mdx b/website/docs/routes/traditional-media.mdx index ef5872940..1b685e0b8 100644 --- a/website/docs/routes/traditional-media.mdx +++ b/website/docs/routes/traditional-media.mdx @@ -1812,6 +1812,28 @@ This route adds the missing photo and Link element. (Offical RSS doesn't have Li | ---- | ---- | ---- | ---- | ---- | -------- | +## 三联生活周刊 {#san-lian-sheng-huo-zhou-kan} + +### 栏目 {#san-lian-sheng-huo-zhou-kan-lan-mu} + +提取文章全文,获得更好的阅读体验。支持所有频道,频道名称见 [杂志栏目](https://www.lifeweek.com.cn/classify?type=2)。例如 [调查栏目](https://www.lifeweek.com.cn/column/9) URL 最后的数字为栏目 ID + + + | 调查 | 热点 | 人物 | 社会 | 经济 | 文化 | + | ---- | ---- | ---- | ---- | ---- | ---- | + | 9 | 6 | 10 | 2 | 3 | 4 | + + +### 标签 {#san-lian-sheng-huo-zhou-kan-biao-qian} + +提取文章全文,获得更好的阅读体验。支持所有标签,标签名称见 [全部标签](https://www.lifeweek.com.cn/classify?type=1)。例如 [社会调查标签](https://www.lifeweek.com.cn/articleList/122) URL 最后的数字为标签 ID + + + | 社会调查 | 社会 | 经济 | 理财 | 热点 | + | -------- | ---- | ---- | ---- | ---- | + | 122 | 21 | 73 | 74 | 123 | + + ## 厦门网 {#xia-men-wang} ### 数字媒体 {#xia-men-wang-shu-zi-mei-ti}