forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hellogithub): hellogithub 添加文章路由 (DIYgod#17779)
* feat(hellogithub): hellogithub 添加文章路由 * fix(hellogithub): 修复文章排序链接错误 - 修正文章排序链接中的路径错误,从根路径改为文章路径 * refactor(hellogithub): simplify route path definitions ---------
- Loading branch information
1 parent
3e87b79
commit 2ee154c
Showing
4 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: `<figure> | ||
<img src="${item.head_image}"> | ||
</figure><br>${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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters