Skip to content

Commit

Permalink
feat(route): 新增 i黑马网 (DIYgod#17843)
Browse files Browse the repository at this point in the history
  • Loading branch information
p3psi-boo authored Dec 11, 2024
1 parent a49355b commit 3cb7925
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
44 changes: 44 additions & 0 deletions lib/routes/iheima/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
path: '/recommend',
categories: ['new-media'],
example: '/iheima/recommend',
url: 'www.iheima.com',
name: '推荐',
maintainers: ['p3psi-boo'],
handler,
};

async function handler() {
const baseUrl = 'https://www.iheima.com/?page=1&pagesize=20';

const response = await got({
method: 'get',
url: baseUrl,
responseType: 'json',
headers: {
Accept: 'application/json, text/javascript, */*; q=0.01',
Referer: 'https://www.iheima.com/',
'X-Requested-With': 'XMLHttpRequest',
},
});

const content = JSON.parse(response.body);
const list = content.contents;

const items = list.map((item) => ({
title: item.title,
link: item.url,
pubDate: parseDate(item.published),
description: item.content,
}));

return {
title: '推荐',
link: baseUrl,
item: items,
};
}
8 changes: 8 additions & 0 deletions lib/routes/iheima/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: 'i黑马网',
url: 'www.iheima.com',
description: '',
lang: 'zh-CN',
};

0 comments on commit 3cb7925

Please sign in to comment.