feat(route): added hackyournews (#13317)

* added hackyournews

* removed the 'Archive' suffix in the title

* cleaned up & fixed line breaks

* cleaned up

* fixed the doc

* resolved
This commit is contained in:
Xiaoxu Guo
2023-09-25 00:07:22 +08:00
committed by GitHub
parent 6309afcccc
commit 75a087dd72
5 changed files with 77 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
// Require necessary modules
const got = require('@/utils/got'); // a customised got
const cheerio = require('cheerio'); // an HTML parser with a jQuery-like API
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const baseUrl = 'https://hackyournews.com';
const { data: response } = await got(baseUrl);
const $ = cheerio.load(response);
const item = $('tr.story')
.map((_, story) => {
const title = $(story).find('a').first().text();
const nextRow = $(story).next();
const metas = nextRow.text().trimStart().split('|');
const upvotes = parseInt(metas[0].split(' points')[0].trim());
const author = metas[0].split('by')[1].trim();
const pubDate = parseDate(metas[1].trim());
let category = [];
// NOTE: If the summary is not already proceeded, we cannot get the category.
if (metas.length === 5) {
category = [metas[2].trim(), metas[3].trim()];
}
const a = nextRow.find('a');
const link = a.attr('href');
const comments = parseInt(a.text());
const description = nextRow
.find('p')
.map((_, p) => $(p).text())
.get()
.join('<br>');
return {
title,
link,
author,
category,
comments,
upvotes,
pubDate,
description,
};
})
.get();
ctx.state.data = {
title: 'Index',
link: baseUrl,
item,
};
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
'/': ['ftiasch'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'hackyournews.com': {
_name: 'HackYourNews',
'.': [
{
title: 'Index',
docs: 'https://docs.rsshub.app/routes/programming#hack-your-news',
source: ['/'],
target: '/hackyournews',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/', require('./index'));
};
+7
View File
@@ -495,6 +495,13 @@ Subscribe to the updates (threads and submission) from a paritcular Hacker News
<Route author="Yukaii kaiix" example="/hackmd/profile/hackmd" path="/hackmd/profile/:path" paramsDesc={['userpath or teampath']} radar="1"/>
## HackYourNews {#hack-your-news}
### Index {#hack-your-news-index}
<Route author="ftiasch" example="/hackyournews" path="/hackyournews" />
## HelloGitHub {#hellogithub}
### 热门 {#hellogithub-re-men}