From 107cc039516295bbe09a8462205a242651fa25e8 Mon Sep 17 00:00:00 2001 From: Bubu <43925055+p3psi-boo@users.noreply.github.com> Date: Wed, 11 Dec 2024 21:11:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=B7=BB=E5=8A=A0=20=E7=99=BD?= =?UTF-8?q?=E9=B2=B8=E5=87=BA=E6=B5=B7=20(#17845)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): 添加白鲸出海 * Update lib/routes/baijing/index.ts * Update lib/routes/baijing/index.ts --- lib/routes/baijing/index.ts | 48 +++++++++++++++++++++++++++++++++ lib/routes/baijing/namespace.ts | 8 ++++++ 2 files changed, 56 insertions(+) create mode 100644 lib/routes/baijing/index.ts create mode 100644 lib/routes/baijing/namespace.ts diff --git a/lib/routes/baijing/index.ts b/lib/routes/baijing/index.ts new file mode 100644 index 00000000000000..79b2bda6b4ae4e --- /dev/null +++ b/lib/routes/baijing/index.ts @@ -0,0 +1,48 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import ofetch from '@/utils/ofetch'; + +export const route: Route = { + path: '/article', + categories: ['new-media'], + example: '/baijing/article', + url: 'www.baijing.cn/article/', + name: '资讯', + maintainers: ['p3psi-boo'], + handler, +}; + +async function handler() { + const apiUrl = 'https://www.baijing.cn/index/ajax/get_article/'; + const response = await ofetch(apiUrl); + const data = response.data.article_list; + + const list = data.map((item) => ({ + title: item.title, + link: `https://www.baijing.cn/article/${item.id}`, + author: item.user_info.user_name, + category: item.topic?.map((t) => t.title), + })); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await ofetch(item.link); + + const $ = load(response); + item.description = $('.content').html(); + item.pubDate = parseDate($('.timeago').text()); + + return item; + }) + ) + ); + + return { + title: '白鲸出海 - 资讯', + link: 'https://www.baijing.cn/article/', + item: items, + }; +} diff --git a/lib/routes/baijing/namespace.ts b/lib/routes/baijing/namespace.ts new file mode 100644 index 00000000000000..57d69294cd4383 --- /dev/null +++ b/lib/routes/baijing/namespace.ts @@ -0,0 +1,8 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '白鲸出海', + url: 'baijing.cn', + description: '白鲸出海', + lang: 'zh-CN', +};