Skip to content

Commit

Permalink
feat(route): add route for Engineering blogs (DIYgod#16529)
Browse files Browse the repository at this point in the history
* 制作imhcg的路由

* 遵循路由规范

* Update lib/routes/imhcg/blog.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/routes/imhcg/blog.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* 修改imhcg的namespace,使其与route name不同

* Update lib/routes/imhcg/namespace.ts

---------
  • Loading branch information
ZiHao256 authored Aug 25, 2024
1 parent df40192 commit 292471e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
47 changes: 47 additions & 0 deletions lib/routes/imhcg/blog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Route, ViewType } from '@/types';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';

export const route: Route = {
path: '/',
categories: ['blog'],
view: ViewType.Notifications,
example: '/',
parameters: {},
radar: [
{
source: ['infos.imhcg.cn'],
},
],
name: 'Engineering blogs',
maintainers: ['ZiHao256'],
handler,
url: 'https://infos.imhcg.cn/',
};

async function handler() {
const response = await ofetch('https://infos.imhcg.cn/');
const $ = load(response);
const items = $('li')
.toArray()
.map((item) => {
const title = $(item).find('a.title').text();
const link = $(item).find('a.title').attr('href');
const author = $(item).find('p.author').text();
const time = $(item).find('p.time').text();
const description = $(item).find('p.text').text();
return {
title,
link,
author,
time,
description,
};
});

return {
title: `Engineering Blogs`,
link: 'https://infos.imhcg.cn/',
item: items,
};
}
7 changes: 7 additions & 0 deletions lib/routes/imhcg/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'imhcg的信息站',
url: 'infos.imhcg.cn',
description: '包含多种技术和新闻信息的网站',
};

0 comments on commit 292471e

Please sign in to comment.