Skip to content

Commit

Permalink
feat(route): 添加 白鲸出海 (#17845)
Browse files Browse the repository at this point in the history
* feat(route): 添加白鲸出海

* Update lib/routes/baijing/index.ts

* Update lib/routes/baijing/index.ts
  • Loading branch information
p3psi-boo authored Dec 11, 2024
1 parent 3cb7925 commit 107cc03
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
48 changes: 48 additions & 0 deletions lib/routes/baijing/index.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}
8 changes: 8 additions & 0 deletions lib/routes/baijing/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '白鲸出海',
url: 'baijing.cn',
description: '白鲸出海',
lang: 'zh-CN',
};

0 comments on commit 107cc03

Please sign in to comment.