-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(route): 添加白鲸出海 * Update lib/routes/baijing/index.ts * Update lib/routes/baijing/index.ts
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; |