From ab884a28be0dbec60a541bc5519542c35fb0e8ff Mon Sep 17 00:00:00 2001 From: Felix Hsu Date: Wed, 5 Oct 2022 21:56:01 +0800 Subject: [PATCH] feat(route): add "over" section on hacker news (#10997) * add hackernews Over section * docs: fix --- docs/en/programming.md | 10 ++++++---- docs/programming.md | 10 ++++++---- lib/v2/hackernews/index.js | 13 ++++++++----- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/docs/en/programming.md b/docs/en/programming.md index a4c743b91..59651e7cf 100644 --- a/docs/en/programming.md +++ b/docs/en/programming.md @@ -249,13 +249,15 @@ For instance, the `/github/topics/framework/l=php&o=desc&s=stars` route will gen ### Section - + 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 diff --git a/docs/programming.md b/docs/programming.md index 3bbe87dc0..699bed439 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -369,13 +369,15 @@ GitHub 官方也提供了一些 RSS: ### 分区 - + 内容分区 -| 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` 分区只显示过去几天内超过固定阈值的帖子。 条目指向链接类型 diff --git a/lib/v2/hackernews/index.js b/lib/v2/hackernews/index.js index c41576ed8..5f547d27d 100644 --- a/lib/v2/hackernews/index.js +++ b/lib/v2/hackernews/index.js @@ -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);