diff --git a/lib/routes/iheima/index.ts b/lib/routes/iheima/index.ts new file mode 100644 index 00000000000000..1f105587d5b2ca --- /dev/null +++ b/lib/routes/iheima/index.ts @@ -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, + }; +} diff --git a/lib/routes/iheima/namespace.ts b/lib/routes/iheima/namespace.ts new file mode 100644 index 00000000000000..b276ca53c5eaf5 --- /dev/null +++ b/lib/routes/iheima/namespace.ts @@ -0,0 +1,8 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'i黑马网', + url: 'www.iheima.com', + description: '', + lang: 'zh-CN', +};