feat(route): add "over" section on hacker news (#10997)

* add hackernews Over section

* docs: fix
This commit is contained in:
Felix Hsu 2022-10-05 21:56:01 +08:00 committed by GitHub
parent fdc59d2d65
commit ab884a28be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 13 deletions

View File

@ -249,13 +249,15 @@ For instance, the `/github/topics/framework/l=php&o=desc&s=stars` route will gen
### Section
<RouteEn author="cf020031308 nczitzk" example="/hackernews" path="/hackernews/:section?/:type?/:user?" :paramsDesc="['Section, see below, `index` by default', 'Link, see below, `sources` by default', 'User, only valid for section `threads` and `submitted`']">
<RouteEn author="cf020031308 nczitzk" example="/hackernews" path="/hackernews/:section?/:type?/:user?" :paramsDesc="['Section, see below, `index` by default', 'Link, see below, `sources` by default', 'User, only valid for section `threads` and `submitted`. When `over` section is used, `User` means the threshold points for post']">
Section
| homepage | new | past | comments | ask | show | jobs | best | threads | submitted |
| ------------------------------------- | --------------------------------------------- | ------------------------------------------- | ------------------------------------------------------- | --------------------------------------- | ----------------------------------------- | ----------------------------------------- | ----------------------------------------- | ------------------------------------------------------- | ----------------------------------------------------------- |
| [index](https://news.ycombinator.com) | [newest](https://news.ycombinator.com/newest) | [front](https://news.ycombinator.com/front) | [newcomments](https://news.ycombinator.com/newcomments) | [ask](https://news.ycombinator.com/ask) | [show](https://news.ycombinator.com/show) | [jobs](https://news.ycombinator.com/jobs) | [best](https://news.ycombinator.com/best) | [threads](https://news.ycombinator.com/threads?id=dang) | [submitted](https://news.ycombinator.com/submitted?id=dang) |
| homepage | new | past | comments | ask | show | jobs | best | threads | submitted |over |
| ------------------------------------- | --------------------------------------------- | ------------------------------------------- | ------------------------------------------------------- | --------------------------------------- | ----------------------------------------- | ----------------------------------------- | ----------------------------------------- | ------------------------------------------------------- | ----------------------------------------------------------- |----------------------------------------------------------- |
| [index](https://news.ycombinator.com) | [newest](https://news.ycombinator.com/newest) | [front](https://news.ycombinator.com/front) | [newcomments](https://news.ycombinator.com/newcomments) | [ask](https://news.ycombinator.com/ask) | [show](https://news.ycombinator.com/show) | [jobs](https://news.ycombinator.com/jobs) | [best](https://news.ycombinator.com/best) | [threads](https://news.ycombinator.com/threads?id=dang) | [submitted](https://news.ycombinator.com/submitted?id=dang) | [over](https://news.ycombinator.com/over?points=100) |
> Section `Over` only shows the submissions over a fixed threshold from last few days
Items link to

View File

@ -369,13 +369,15 @@ GitHub 官方也提供了一些 RSS:
### 分区
<Route author="cf020031308 nczitzk" example="/hackernews" path="/hackernews/:section?/:type?/:user?" :paramsDesc="['内容分区,见下表,默认为 `index`', '链接类型,见下表,默认为 `sources`', '设定用户,只在 `threads``submitted` 分区有效']">
<Route author="cf020031308 nczitzk" example="/hackernews" path="/hackernews/:section?/:type?/:user?" :paramsDesc="['内容分区,见下表,默认为 `index`', '链接类型,见下表,默认为 `sources`', '设定用户,只在 `threads``submitted` 分区有效。斜当选择`over`分区,`User`的含义是帖子点数的阈值']">
内容分区
| homepage | new | past | comments | ask | show | jobs | best | threads | submitted |
| ------------------------------------- | --------------------------------------------- | ------------------------------------------- | ------------------------------------------------------- | --------------------------------------- | ----------------------------------------- | ----------------------------------------- | ----------------------------------------- | ------------------------------------------------------- | ----------------------------------------------------------- |
| [index](https://news.ycombinator.com) | [newest](https://news.ycombinator.com/newest) | [front](https://news.ycombinator.com/front) | [newcomments](https://news.ycombinator.com/newcomments) | [ask](https://news.ycombinator.com/ask) | [show](https://news.ycombinator.com/show) | [jobs](https://news.ycombinator.com/jobs) | [best](https://news.ycombinator.com/best) | [threads](https://news.ycombinator.com/threads?id=dang) | [submitted](https://news.ycombinator.com/submitted?id=dang) |
| homepage | new | past | comments | ask | show | jobs | best | threads | submitted | over |
| ------------------------------------- | --------------------------------------------- | ------------------------------------------- | ------------------------------------------------------- | --------------------------------------- | ----------------------------------------- | ----------------------------------------- | ----------------------------------------- | ------------------------------------------------------- | ----------------------------------------------------------- | ---------------------------------------------------- |
| [index](https://news.ycombinator.com) | [newest](https://news.ycombinator.com/newest) | [front](https://news.ycombinator.com/front) | [newcomments](https://news.ycombinator.com/newcomments) | [ask](https://news.ycombinator.com/ask) | [show](https://news.ycombinator.com/show) | [jobs](https://news.ycombinator.com/jobs) | [best](https://news.ycombinator.com/best) | [threads](https://news.ycombinator.com/threads?id=dang) | [submitted](https://news.ycombinator.com/submitted?id=dang) | [over](https://news.ycombinator.com/over?points=100) |
> `Over` 分区只显示过去几天内超过固定阈值的帖子。
条目指向链接类型

View File

@ -8,12 +8,15 @@ module.exports = async (ctx) => {
const user = ctx.params.user ?? '';
const rootUrl = 'https://news.ycombinator.com';
const currentUrl = `${rootUrl}${section === 'index' ? '' : `/${section}`}${user === '' ? '' : '?id=' + user}`;
const sectionUrl = section === 'index' ? '' : `/${section}`;
let optUrl = user === '' ? '' : '?id=' + user;
const response = await got({
method: 'get',
url: currentUrl,
});
if (section === 'over') {
optUrl = user === '' ? '?points=100' : '?points=' + user;
}
const currentUrl = `${rootUrl}${sectionUrl}${optUrl}`;
const response = await got(currentUrl);
const $ = cheerio.load(response.data);