Skip to content

Commit 2ee154c

Browse files
authored
feat(hellogithub): hellogithub 添加文章路由 (#17779)
* feat(hellogithub): hellogithub 添加文章路由 * fix(hellogithub): 修复文章排序链接错误 - 修正文章排序链接中的路径错误,从根路径改为文章路径 * refactor(hellogithub): simplify route path definitions ---------
1 parent 3e87b79 commit 2ee154c

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

lib/routes/hellogithub/article.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { Route } from '@/types';
2+
3+
import got from '@/utils/got';
4+
import { parseDate } from '@/utils/parse-date';
5+
6+
const sorts = {
7+
hot: '热门',
8+
last: '最近',
9+
};
10+
11+
export const route: Route = {
12+
path: '/article/:sort?',
13+
categories: ['programming'],
14+
example: '/hellogithub/article',
15+
parameters: { sort: '排序方式,见下表,默认为 `last`,即最近' },
16+
features: {
17+
requireConfig: false,
18+
requirePuppeteer: false,
19+
antiCrawler: false,
20+
supportBT: false,
21+
supportPodcast: false,
22+
supportScihub: false,
23+
},
24+
name: '文章',
25+
maintainers: ['moke8', 'nczitzk', 'CaoMeiYouRen'],
26+
handler,
27+
description: `| 热门 | 最近 |
28+
| ---- | ---- |
29+
| hot | last |`,
30+
};
31+
32+
async function handler(ctx) {
33+
const sort = ctx.req.param('sort') ?? 'last';
34+
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20;
35+
36+
const rootUrl = 'https://hellogithub.com';
37+
const apiRootUrl = 'https://api.hellogithub.com/v1/article/';
38+
const currentUrl = `${rootUrl}/article/?sort_by=${sort}`;
39+
const apiUrl = `${apiRootUrl}?sort_by=${sort}&page=1`;
40+
41+
const response = await got({
42+
method: 'get',
43+
url: apiUrl,
44+
});
45+
46+
const items = response.data.data.slice(0, limit).map((item) => ({
47+
title: item.title,
48+
description: `<figure>
49+
<img src="${item.head_image}">
50+
</figure><br>${item.desc}`,
51+
link: `${rootUrl}/article/${item.aid}`,
52+
author: item.author,
53+
guid: item.aid,
54+
pubDate: parseDate(item.publish_at),
55+
}));
56+
57+
return {
58+
title: `HelloGithub - ${sorts[sort]}文章`,
59+
link: currentUrl,
60+
item: items,
61+
};
62+
}

lib/routes/hellogithub/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const sorts = {
1010
};
1111

1212
export const route: Route = {
13-
path: ['/home/:sort?/:id?'],
13+
path: '/home/:sort?/:id?',
1414
categories: ['programming'],
1515
example: '/hellogithub/home',
1616
parameters: { sort: '排序方式,见下表,默认为 `featured`,即精选', id: '标签 id,可在对应标签页 URL 中找到,默认为全部标签' },
@@ -23,7 +23,7 @@ export const route: Route = {
2323
supportScihub: false,
2424
},
2525
name: '开源项目',
26-
maintainers: ['moke8', 'nczitzk'],
26+
maintainers: ['moke8', 'nczitzk', 'CaoMeiYouRen'],
2727
handler,
2828
description: `| 精选 | 全部 |
2929
| ---- | ---- |

lib/routes/hellogithub/report.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const types = {
1414
};
1515

1616
export const route: Route = {
17-
path: ['/ranking/:type?', '/report/:type?'],
17+
path: '/ranking/:type?',
1818
example: '/hellogithub/ranking',
1919
name: '榜单报告',
2020
maintainers: ['moke8', 'nczitzk'],

lib/routes/hellogithub/volume.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ art.defaults.imports.render = function (string) {
1919
};
2020

2121
export const route: Route = {
22-
path: ['/month', '/volume'],
22+
path: '/volume',
2323
example: '/hellogithub/volume',
2424
name: '月刊',
2525
maintainers: ['moke8', 'nczitzk', 'CaoMeiYouRen'],

0 commit comments

Comments
 (0)