From 5b4173403a39a6dcae6808dc748719466c7052a0 Mon Sep 17 00:00:00 2001 From: Bubu <43925055+p3psi-boo@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:02:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=96=B0=E5=A2=9E=20=E6=96=B0?= =?UTF-8?q?=E8=8A=BD=E7=BD=91=20(#17841)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/newseed/index.ts | 73 +++++++++++++++++++++++++++++++++ lib/routes/newseed/namespace.ts | 8 ++++ 2 files changed, 81 insertions(+) create mode 100644 lib/routes/newseed/index.ts create mode 100644 lib/routes/newseed/namespace.ts diff --git a/lib/routes/newseed/index.ts b/lib/routes/newseed/index.ts new file mode 100644 index 00000000000000..03b4906d61e989 --- /dev/null +++ b/lib/routes/newseed/index.ts @@ -0,0 +1,73 @@ +import { Route } from '@/types'; + +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; + +export const route: Route = { + path: '/latest', + categories: ['new-media'], + example: '/newseed/latest', + url: 'news.newseed.cn', + name: '最新新闻', + maintainers: ['p3psi-boo'], + handler, +}; + +async function handler() { + const baseUrl = 'https://news.newseed.cn/'; + const response = await got({ + method: 'get', + url: baseUrl, + }); + + const $ = load(response.data); + + const list = $('#news-list li') + .toArray() + .map((item) => { + const element = $(item); + const a = element.find('h3 a'); + const link = a.attr('href') || ''; + const title = a.text(); + const image = element.find('.img img').attr('src'); + const info = element.find('.info'); + const author = info.find('.author a').text(); + const pubDate = info.find('.date').text(); + const tags = element + .find('.tag a') + .toArray() + .map((el) => $(el).text()) + .filter((tag) => tag !== author); + + return { + title, + link, + author, + pubDate, + category: tags, + description: image ? `
${title}` : title, + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await got({ + method: 'get', + url: item.link, + }); + + const $ = load(response.data); + item.description = $('.news-content').html() || item.description; + return item; + }) + ) + ); + + return { + title: '新芽 - 最新新闻', + link: baseUrl, + item: items, + }; +} diff --git a/lib/routes/newseed/namespace.ts b/lib/routes/newseed/namespace.ts new file mode 100644 index 00000000000000..9ae79a97b8ca34 --- /dev/null +++ b/lib/routes/newseed/namespace.ts @@ -0,0 +1,8 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '新芽', + url: 'newseed.cn', + description: '新芽是专注于互联网创业的媒体平台,提供创业资讯、投融资信息、创业活动、创业服务等。', + lang: 'zh-CN', +};