feat: 为印记中文周刊rss增加完整文章抓取 (#14727)
* 修复印记中文js周刊rss * 更新docschina路由和周刊模块 * Update lib/routes/docschina/router.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/routes/docschina/maintainer.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * 移除无用的代码和变量声明 * 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 ---------
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user