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, }; }