mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
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:
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
'/': ['ftiasch'],
|
||||
};
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/', require('./index'));
|
||||
};
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user