From 55b0a5a2dddb616c5483aaa38bbb1b2023095dea 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: Sat, 16 Mar 2024 04:22:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BA=E5=8D=B0=E8=AE=B0=E4=B8=AD?= =?UTF-8?q?=E6=96=87=E5=91=A8=E5=88=8Arss=E5=A2=9E=E5=8A=A0=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=E6=96=87=E7=AB=A0=E6=8A=93=E5=8F=96=20(#14727)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复印记中文js周刊rss * 更新docschina路由和周刊模块 * Update lib/routes/docschina/router.ts Co-authored-by: Tony * Update lib/routes/docschina/maintainer.ts Co-authored-by: Tony * 移除无用的代码和变量声明 * fix: radar * feat: 印记中文周刊增加完整文章抓取 * 更新docschina/weekly.ts文件中的代码 * Revert "Merge branch 'master' into master" This reverts commit c6ad102cb1b2dd53729520f8f10c5ba71ed8ab2d, reversing changes made to 8487eecef354f49427bd002b5fa3ffea76dcd856. * Revert "Revert "Merge branch 'master' into master"" This reverts commit a9674e782e11b9ee17faec6856f28d635530fcf8. * 更新周报路由处理函数 * refactor: migrate to v3 --------- --- lib/routes/docschina/weekly.ts | 57 ++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/lib/routes/docschina/weekly.ts b/lib/routes/docschina/weekly.ts index df79dec7d..0a04c50f0 100644 --- a/lib/routes/docschina/weekly.ts +++ b/lib/routes/docschina/weekly.ts @@ -1,23 +1,32 @@ import { Route } from '@/types'; import got from '@/utils/got'; import { load } from 'cheerio'; +import cache from '@/utils/cache'; +import markdownit from 'markdown-it'; + +const md = markdownit({ + html: true, + breaks: true, +}); export const route: Route = { path: '/weekly/:category?', categories: ['programming'], example: '/docschina/weekly', parameters: { category: '周刊分类,见下表,默认为js' }, - features: { - requireConfig: false, - requirePuppeteer: false, - antiCrawler: false, - supportBT: false, - supportPodcast: false, - supportScihub: false, - }, - name: 'Unknown', + name: '周刊 - JavaScript', maintainers: ['daijinru', 'hestudy'], handler, + description: ` + | javascript | node | react | + | ---------- | ---- | ----- | + | js | node | react |`, + radar: [ + { + source: ['docschina.org/news/weekly/js/*', 'docschina.org/news/weekly/js', 'docschina.org/'], + target: '/jsweekly', + }, + ], }; async function handler(ctx) { @@ -25,8 +34,8 @@ async function handler(ctx) { const baseURL = 'https://docschina.org'; const path = `/news/weekly/${category}`; - const { data: res } = await got(`${baseURL}${path}`); - + const url = `${baseURL}${path}`; + const { data: res } = await got(url); // @ts-ignore const $ = load(res); @@ -34,15 +43,25 @@ async function handler(ctx) { const dataEl = $('#__NEXT_DATA__'); const dataText = dataEl.text(); const data = JSON.parse(dataText); + const items = await Promise.all( + data?.props?.pageProps?.data?.slice(0, 10).map((item) => { + const link = `${url}/${item.issue}`; + return cache.tryGet(link, async () => { + const { data: response } = await got(`${baseURL}/_next/data/${data.buildId}/news/weekly/js/${item.issue}.json`); + return { + title: item.title, + description: md.render(response.pageProps.content), + link, + author: item.editors?.join(','), + itunes_item_image: item.imageUrl, + }; + }); + }) || {} + ); + return { 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, - })), + link: url, + item: items, }; }