Skip to content

Commit

Permalink
feat(route): 新增动脉网
Browse files Browse the repository at this point in the history
  • Loading branch information
p3psi-boo committed Dec 11, 2024
1 parent 17e2fc7 commit 4cab054
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
56 changes: 56 additions & 0 deletions lib/routes/vbdata/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Route } from '@/types';

import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
path: '/news',
categories: ['new-media'],
example: '/vbdata/news/',
url: 'www.vbdata.cn/v2',
name: '最新资讯',
maintainers: ['p3psi-boo'],
handler,
};

async function handler() {
const baseUrl = 'https://www.vbdata.cn/v2';
const response = await ofetch(baseUrl);

const $ = load(response);
const list = $('ul.special > li')
.map((_, item) => {
const $item = $(item).find('.spc_cnt');
const $link = $item.find('a').first();

return {
title: $link.text().trim(),
link: new URL($link.attr('href') || '', baseUrl).href,
};
})
.toArray()

Check warning

Code scanning / ESLint

Disallow specified syntax Warning

Please use .toArray() before .map().
.filter((item) => item.title && item.title !== '');

const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const response = await ofetch(item.link);

const $ = load(response);
const cardInfo = $('.card-info');
item.description = $('.content').html();
item.pubDate = parseDate(cardInfo.find('.spa2').text());
item.author = cardInfo.find('.spa1').text();
return item;
})
)
);

return {
title: '动脉网 - 最新资讯',
link: baseUrl,
item: items,
};
}
8 changes: 8 additions & 0 deletions lib/routes/vbdata/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: 'vbdata.cn',
description: '',
lang: 'zh-CN',
};

0 comments on commit 4cab054

Please sign in to comment.