From 4ebfcf7d4a91681928f04af3b4400a2a57436ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=8E=E4=B9=88=E5=AD=A6=E9=83=BD=E5=AD=A6=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E7=9A=84=E4=BD=95=E5=90=8C=E5=AD=A6?= <1467602180@qq.com> Date: Fri, 8 Mar 2024 22:24:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8D=B0=E8=AE=B0?= =?UTF-8?q?=E4=B8=AD=E6=96=87=E5=91=A8=E5=88=8Arss=20feat:=20=E4=B8=BA?= =?UTF-8?q?=E5=8D=B0=E8=AE=B0=E4=B8=AD=E6=96=87rss=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=88=86=E7=B1=BB=20(#14720)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复印记中文js周刊rss * 更新docschina路由和周刊模块 * Update lib/routes/docschina/router.ts * Update lib/routes/docschina/maintainer.ts * 移除无用的代码和变量声明 * fix: radar --------- --- lib/routes/docschina/jsweekly.ts | 116 ---------------------------- lib/routes/docschina/maintainer.ts | 2 +- lib/routes/docschina/radar.ts | 4 +- lib/routes/docschina/router.ts | 2 +- lib/routes/docschina/weekly.ts | 29 +++++++ website/docs/routes/programming.mdx | 6 +- 6 files changed, 38 insertions(+), 121 deletions(-) delete mode 100644 lib/routes/docschina/jsweekly.ts create mode 100644 lib/routes/docschina/weekly.ts diff --git a/lib/routes/docschina/jsweekly.ts b/lib/routes/docschina/jsweekly.ts deleted file mode 100644 index 3404bbbff..000000000 --- a/lib/routes/docschina/jsweekly.ts +++ /dev/null @@ -1,116 +0,0 @@ -import cache from '@/utils/cache'; -import got from '@/utils/got'; -import { load } from 'cheerio'; -import MarkdownIt from 'markdown-it'; -const md = MarkdownIt(); - -export default async (ctx) => { - const baseURL = 'https://docschina.org'; - const { data: res } = await got(`${baseURL}/weekly/js/docs/`); - - const $ = load(res); - - const title = $('head title').text(); - const vendorLink = $('body script') - .toArray() - .find((i) => - $(i) - .attr('src') - .match(/vendor/) - ).attribs.src; - - const { data: vendor } = await got(`https:${vendorLink}`); - const env = vendor.match(/default.init\({env:"(.*?)"}\)/)[1]; // docschina-live-10765e - const dataVersion = vendor.match(/,dataVersion:"(\d{4}-\d{2}-\d{2})",/)[1]; // 2020-01-10 - - // const seqId = Math.random().toString(16).slice(2); - const { data: document } = await got.post('https://tcb-api.tencentcloudapi.com/web', { - headers: { - origin: 'https://docschina.org', - // referer: 'https://docschina.org/', - // 'x-sdk-version': '@cloudbase/js-sdk/1.3.3', - // 'x-seqid': seqId, - }, - searchParams: { - env, - }, - json: { - action: 'database.queryDocument', - collectionName: 'js_weekly_document', - dataVersion, - env, - limit: 100, - query: JSON.stringify({ - path: '/', - }), - queryType: 'WHERE', - // seqId, - }, - }); - - const { data: sidebar } = await got.post('https://tcb-api.tencentcloudapi.com/web', { - headers: { - origin: 'https://docschina.org', - }, - searchParams: { - env, - }, - json: { - action: 'database.queryDocument', - collectionName: 'js_weekly_sidebar', - dataVersion, - env, - limit: 100, - query: JSON.stringify({ - pages: { - $in: [document.data.list[0]._id], - }, - }), - }, - }); - - const list = sidebar.data.list[0].value - .filter((i) => i.key !== 'home') - .map((i) => ({ - title: i.title, - link: `${baseURL}/weekly/js${i.path}`, - key: i.key, - })); - - const items = await Promise.all( - list.map((item) => - cache.tryGet(item.link, async () => { - const { data: document } = await got.post('https://tcb-api.tencentcloudapi.com/web', { - headers: { - origin: 'https://docschina.org', - }, - searchParams: { - env, - }, - json: { - action: 'database.queryDocument', - collectionName: 'js_weekly_document', - dataVersion, - env, - limit: 100, - query: JSON.stringify({ - path: item.key, - }), - }, - }); - - item.description = md.render(document.data.list[0].content); - - delete item.key; - return item; - }) - ) - ); - - ctx.set('data', { - title, - link: `${baseURL}/weekly/js/docs/`, - icon: 'https://docschina.org/favicon.ico', - item: items, - }); -}; diff --git a/lib/routes/docschina/maintainer.ts b/lib/routes/docschina/maintainer.ts index 08e5de398..96f00dd8e 100644 --- a/lib/routes/docschina/maintainer.ts +++ b/lib/routes/docschina/maintainer.ts @@ -1,3 +1,3 @@ export default { - '/jsweekly': ['daijinru'], + '/weekly/:category?': ['daijinru', 'hestudy'], }; diff --git a/lib/routes/docschina/radar.ts b/lib/routes/docschina/radar.ts index ca33da825..96fdd36b6 100644 --- a/lib/routes/docschina/radar.ts +++ b/lib/routes/docschina/radar.ts @@ -1,11 +1,11 @@ export default { - docschina: { + 'docschina.org': { _name: '印记中文', '.': [ { title: '周刊 - JavaScript', docs: 'https://docs.rsshub.app/routes/programming#yin-ji-zhong-wen-zhou-kan', - source: ['/weekly/js/*', '/weekly/js', '/'], + source: ['/news/weekly/js/*', '/news/weekly/js', '/'], target: '/docschina/jsweekly', }, ], diff --git a/lib/routes/docschina/router.ts b/lib/routes/docschina/router.ts index c120fac13..ced43d0af 100644 --- a/lib/routes/docschina/router.ts +++ b/lib/routes/docschina/router.ts @@ -1,3 +1,3 @@ export default (router) => { - router.get('/jsweekly', './jsweekly'); + router.get('/weekly/:category?', './weekly'); }; diff --git a/lib/routes/docschina/weekly.ts b/lib/routes/docschina/weekly.ts new file mode 100644 index 000000000..b81eb4273 --- /dev/null +++ b/lib/routes/docschina/weekly.ts @@ -0,0 +1,29 @@ +import got from '@/utils/got'; +import { load } from 'cheerio'; + +export default async (ctx) => { + const { category = 'js' } = ctx.req.param(); + + const baseURL = 'https://docschina.org'; + const path = `/news/weekly/${category}`; + const { data: res } = await got(`${baseURL}${path}`); + + // @ts-ignore + const $ = load(res); + + const title = $('head title').text(); + const dataEl = $('#__NEXT_DATA__'); + const dataText = dataEl.text(); + const data = JSON.parse(dataText); + ctx.set('data', { + title, + link: baseURL + path, + item: data?.props?.pageProps?.data?.map((item) => ({ + title: item.title, + description: item.description, + link: `${baseURL}${path}/${item.issue}`, + author: item.editors?.join(','), + itunes_item_image: item.imageUrl, + })), + }); +}; diff --git a/website/docs/routes/programming.mdx b/website/docs/routes/programming.mdx index 6420c7e33..97cf7c56d 100644 --- a/website/docs/routes/programming.mdx +++ b/website/docs/routes/programming.mdx @@ -1141,4 +1141,8 @@ Stay up to date on the latest React news, tutorials, resources, and more. Delive ### 周刊 - JavaScript {#yin-ji-zhong-wen-zhou-kan-javascript} - + + | javascript | node | react | + | ---------- | ---- | ----- | + | js | node | react | +