From 2ee154c2d8c7b431834873db0e768b1091cff70c Mon Sep 17 00:00:00 2001
From: CaoMeiYouRen <40430746+CaoMeiYouRen@users.noreply.github.com>
Date: Tue, 3 Dec 2024 22:11:15 +0800
Subject: [PATCH] =?UTF-8?q?feat(hellogithub):=20hellogithub=20=E6=B7=BB?=
=?UTF-8?q?=E5=8A=A0=E6=96=87=E7=AB=A0=E8=B7=AF=E7=94=B1=20(#17779)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(hellogithub): hellogithub 添加文章路由
* fix(hellogithub): 修复文章排序链接错误
- 修正文章排序链接中的路径错误,从根路径改为文章路径
* refactor(hellogithub): simplify route path definitions
---------
---
lib/routes/hellogithub/article.ts | 62 +++++++++++++++++++++++++++++++
lib/routes/hellogithub/index.ts | 4 +-
lib/routes/hellogithub/report.ts | 2 +-
lib/routes/hellogithub/volume.ts | 2 +-
4 files changed, 66 insertions(+), 4 deletions(-)
create mode 100644 lib/routes/hellogithub/article.ts
diff --git a/lib/routes/hellogithub/article.ts b/lib/routes/hellogithub/article.ts
new file mode 100644
index 00000000000000..7d2f09ec6efb74
--- /dev/null
+++ b/lib/routes/hellogithub/article.ts
@@ -0,0 +1,62 @@
+import { Route } from '@/types';
+
+import got from '@/utils/got';
+import { parseDate } from '@/utils/parse-date';
+
+const sorts = {
+ hot: '热门',
+ last: '最近',
+};
+
+export const route: Route = {
+ path: '/article/:sort?',
+ categories: ['programming'],
+ example: '/hellogithub/article',
+ parameters: { sort: '排序方式,见下表,默认为 `last`,即最近' },
+ features: {
+ requireConfig: false,
+ requirePuppeteer: false,
+ antiCrawler: false,
+ supportBT: false,
+ supportPodcast: false,
+ supportScihub: false,
+ },
+ name: '文章',
+ maintainers: ['moke8', 'nczitzk', 'CaoMeiYouRen'],
+ handler,
+ description: `| 热门 | 最近 |
+ | ---- | ---- |
+ | hot | last |`,
+};
+
+async function handler(ctx) {
+ const sort = ctx.req.param('sort') ?? 'last';
+ const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20;
+
+ const rootUrl = 'https://hellogithub.com';
+ const apiRootUrl = 'https://api.hellogithub.com/v1/article/';
+ const currentUrl = `${rootUrl}/article/?sort_by=${sort}`;
+ const apiUrl = `${apiRootUrl}?sort_by=${sort}&page=1`;
+
+ const response = await got({
+ method: 'get',
+ url: apiUrl,
+ });
+
+ const items = response.data.data.slice(0, limit).map((item) => ({
+ title: item.title,
+ description: `
${item.desc}`,
+ link: `${rootUrl}/article/${item.aid}`,
+ author: item.author,
+ guid: item.aid,
+ pubDate: parseDate(item.publish_at),
+ }));
+
+ return {
+ title: `HelloGithub - ${sorts[sort]}文章`,
+ link: currentUrl,
+ item: items,
+ };
+}
diff --git a/lib/routes/hellogithub/index.ts b/lib/routes/hellogithub/index.ts
index 877a9e37c40271..0e4790760ebc76 100644
--- a/lib/routes/hellogithub/index.ts
+++ b/lib/routes/hellogithub/index.ts
@@ -10,7 +10,7 @@ const sorts = {
};
export const route: Route = {
- path: ['/home/:sort?/:id?'],
+ path: '/home/:sort?/:id?',
categories: ['programming'],
example: '/hellogithub/home',
parameters: { sort: '排序方式,见下表,默认为 `featured`,即精选', id: '标签 id,可在对应标签页 URL 中找到,默认为全部标签' },
@@ -23,7 +23,7 @@ export const route: Route = {
supportScihub: false,
},
name: '开源项目',
- maintainers: ['moke8', 'nczitzk'],
+ maintainers: ['moke8', 'nczitzk', 'CaoMeiYouRen'],
handler,
description: `| 精选 | 全部 |
| ---- | ---- |
diff --git a/lib/routes/hellogithub/report.ts b/lib/routes/hellogithub/report.ts
index 96a5f4ac918119..dcf3f97eb05f93 100644
--- a/lib/routes/hellogithub/report.ts
+++ b/lib/routes/hellogithub/report.ts
@@ -14,7 +14,7 @@ const types = {
};
export const route: Route = {
- path: ['/ranking/:type?', '/report/:type?'],
+ path: '/ranking/:type?',
example: '/hellogithub/ranking',
name: '榜单报告',
maintainers: ['moke8', 'nczitzk'],
diff --git a/lib/routes/hellogithub/volume.ts b/lib/routes/hellogithub/volume.ts
index 1282068fba2676..5e1f41b9b174cb 100644
--- a/lib/routes/hellogithub/volume.ts
+++ b/lib/routes/hellogithub/volume.ts
@@ -19,7 +19,7 @@ art.defaults.imports.render = function (string) {
};
export const route: Route = {
- path: ['/month', '/volume'],
+ path: '/volume',
example: '/hellogithub/volume',
name: '月刊',
maintainers: ['moke8', 'nczitzk', 'CaoMeiYouRen'],