From 4255b79103afe26b970a67ebd9c5a4f86f910462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E6=97=A5=E7=BB=87?= <43875377+guicaiyue@users.noreply.github.com> Date: Fri, 14 Jun 2024 21:57:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=96=B0=E5=A2=9E=E7=9F=A5?= =?UTF-8?q?=E9=97=BBAI=E8=B5=84=E8=AE=AF=20(#15885)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update:支持知闻AI资讯 * update:更新规范 * update:url描述调整 --- lib/routes/informedainews/docs.ts | 78 ++++++++++++++++++++++++++ lib/routes/informedainews/namespace.ts | 18 ++++++ 2 files changed, 96 insertions(+) create mode 100644 lib/routes/informedainews/docs.ts create mode 100644 lib/routes/informedainews/namespace.ts diff --git a/lib/routes/informedainews/docs.ts b/lib/routes/informedainews/docs.ts new file mode 100644 index 00000000000000..4838ee5f9aa617 --- /dev/null +++ b/lib/routes/informedainews/docs.ts @@ -0,0 +1,78 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; // 统一使用的请求库 +import { load } from 'cheerio'; // 类似 jQuery 的 API HTML 解析器 +import { parseDate } from '@/utils/parse-date'; +import cache from '@/utils/cache'; + +export const route: Route = { + path: '/zh-Hans/docs/:type', + categories: ['new-media'], + example: '/informedainews/zh-Hans/docs/world-news-daily', + parameters: { type: 'world-news-daily|tech-enthusiast-weekly|ai-enthusiast-daily' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['informedainews.com', 'informedainews.com/zh-Hans/docs/:type', 'informedainews.com/docs/:type'], + target: '/zh-Hans/docs/:type', + }, + ], + name: '知闻AI', + maintainers: ['guicaiyue'], + handler, +}; + +async function handler(ctx) { + const { type } = ctx.req.param(); + const response = await ofetch(`https://informedainews.com/zh-Hans/docs/${type}`); + const $ = load(response); + const list = $('li.theme-doc-sidebar-item-category ul li') + .toArray() + .map((item) => { + item = $(item); + const a = item.find('a').first(); + const text = a.text(); + // 找到第一个'('字符的位置 + const start = text.indexOf('('); + // 找到第一个')'字符的位置 + const end = text.indexOf(')'); + // 从第一个'('到第一个')'之间的子字符串就是日期 + const date = text.substring(start + 1, end); + return { + title: text, + link: `https://informedainews.com${a.attr('href')}`, + pubDate: parseDate(date), + author: 'AI', + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await ofetch(item.link); + const $ = load(response); + + // 选择类名为“comment-body”的第一个元素 + item.description = $('.theme-doc-markdown.markdown').first().html(); + + // 上面每个列表项的每个属性都在此重用, + // 并增加了一个新属性“description” + return item; + }) + ) + ); + return { + // 源标题 + title: `${type} docs`, + // 源链接 + link: `https://informedainews.com/zh-Hans/docs/${type}`, + // 源文章 + item: items, + }; +} diff --git a/lib/routes/informedainews/namespace.ts b/lib/routes/informedainews/namespace.ts new file mode 100644 index 00000000000000..0fff54e67ba28e --- /dev/null +++ b/lib/routes/informedainews/namespace.ts @@ -0,0 +1,18 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Informed AI News', + url: 'informedainews.com', + description: ` +:::tip +informed AI RSS feeds: + +- World News Daily: 'https://rsshub.app/informedainews/zh-Hans/docs/world-news-daily' +- Tech Enthusiast Weekly: 'https://rsshub.app/informedainews/zh-Hans/docs/tech-enthusiast-weekly' +- AI Enthusiast Weekly: 'https://rsshub.app/informedainews/zh-Hans/docs/ai-enthusiast-daily' +:::`, + + zh: { + name: '知闻AI', + }, +};