mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat: add gwern (#6021)
This commit is contained in:
@@ -16,6 +16,10 @@ pageClass: routes
|
||||
|
||||
<Route author="hoilc" example="/google/sites/outlierseconomics" path="/google/sites/:id" :paramsDesc="['Site ID, 可在 URL 中找到']" radar="1" rssbud="1"/>
|
||||
|
||||
## Gwern Branwen
|
||||
|
||||
<Route author="cerebrater" example="/gwern/newest" path="/gwern/:category" :paramsDesc="['網誌主頁的分類訊息']"/>
|
||||
|
||||
## Hedwig.pub
|
||||
|
||||
<Route author="zwithz" example="/blogs/hedwig/zmd" path="/blogs/hedwig/:type" :paramsDesc="['分类, 见下表']"/>
|
||||
|
||||
@@ -468,6 +468,9 @@ router.get('/xueqiu/hots', require('./routes/xueqiu/hots'));
|
||||
// Greasy Fork
|
||||
router.get('/greasyfork/:language/:domain?', require('./routes/greasyfork/scripts'));
|
||||
|
||||
// Gwern Branwen
|
||||
router.get('/gwern/:category', require('./routes/gwern/category'));
|
||||
|
||||
// LinkedKeeper
|
||||
router.get('/linkedkeeper/:type/:id?', require('./routes/linkedkeeper/index'));
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category;
|
||||
const name = category.charAt(0).toUpperCase() + category.slice(1);
|
||||
const baseURL = `https://www.gwern.net`;
|
||||
const url = baseURL + `/index`;
|
||||
const res = await got.get(url);
|
||||
const $ = cheerio.load(res.data);
|
||||
const list = $(`section#${category} ul > li`).get();
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const grasp = cheerio.load(item);
|
||||
const link = baseURL + grasp('a').attr('href');
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const res = await got.get(link);
|
||||
const $ = cheerio.load(res.data);
|
||||
|
||||
const title = $('header > h1').text();
|
||||
const time = $('span#page-creation').text();
|
||||
// const modified = $('span#page-modified').text();
|
||||
|
||||
$('a').each((index, item) => {
|
||||
item = $(item);
|
||||
item.removeAttr('data-popup-title');
|
||||
item.removeAttr('data-popup-title-html');
|
||||
item.removeAttr('data-popup-author');
|
||||
item.removeAttr('data-popup-abstract');
|
||||
item.removeAttr('data-popup-doi');
|
||||
item.removeAttr('data-popup-date');
|
||||
});
|
||||
$;
|
||||
|
||||
const contents = $('div#markdownBody').html().replace('­', '');
|
||||
|
||||
const single = {
|
||||
title: title,
|
||||
author: 'Gwern Branwen',
|
||||
description: contents,
|
||||
link: link,
|
||||
guid: link,
|
||||
pubDate: new Date(time).toUTCString(),
|
||||
};
|
||||
ctx.cache.set(link, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: `Gwern - ${name}`,
|
||||
link: url,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user