mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-06 05:03:44 +08:00
feat(route): add Distill (#8491)
This commit is contained in:
@@ -16,6 +16,12 @@ pageClass: routes
|
||||
|
||||
<RouteEn author="fengkx" example="/cve/search/PostgreSQL" path="/cve/search/:keyword" :paramsDesc="['keyword']" />
|
||||
|
||||
## Distill
|
||||
|
||||
### Latest
|
||||
|
||||
<RouteEn author="nczitzk" example="/distill" path="/distill"/>
|
||||
|
||||
## GitHub
|
||||
|
||||
::: tip
|
||||
|
||||
@@ -58,6 +58,12 @@ pageClass: routes
|
||||
|
||||
<Route author="nczitzk" example="/deeplearningai/thebatch" path="/deeplearningai/thebatch"/>
|
||||
|
||||
## Distill
|
||||
|
||||
### Latest
|
||||
|
||||
<Route author="nczitzk" example="/distill" path="/distill"/>
|
||||
|
||||
## Dockone
|
||||
|
||||
### 周报
|
||||
|
||||
64
lib/v2/distill/index.js
Normal file
64
lib/v2/distill/index.js
Normal file
@@ -0,0 +1,64 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'https://distill.pub';
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: rootUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
let items = $('.post-preview')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
return {
|
||||
title: item.find('.title').text(),
|
||||
link: `${rootUrl}/${item.children('a').attr('href')}`,
|
||||
};
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
content('d-contents').remove();
|
||||
|
||||
content('img').each(function () {
|
||||
content(this).attr('src', `${item.link}/${content(this).attr('src')}`);
|
||||
});
|
||||
|
||||
item.doi = content('meta[name="citation_doi"]').attr('content');
|
||||
item.pubDate = parseDate(content('meta[property="article:published"]').attr('content'));
|
||||
item.description = content('d-article')
|
||||
.children()
|
||||
.toArray()
|
||||
.map((c) => content(c).html())
|
||||
.join('');
|
||||
item.author = content('meta[property="article:author"]')
|
||||
.toArray()
|
||||
.map((author) => content(author).attr('content'))
|
||||
.join(', ');
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: rootUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
3
lib/v2/distill/maintainer.js
Normal file
3
lib/v2/distill/maintainer.js
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/': ['nczitzk'],
|
||||
};
|
||||
13
lib/v2/distill/radar.js
Normal file
13
lib/v2/distill/radar.js
Normal file
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'distill.pub': {
|
||||
_name: 'Distill',
|
||||
'.': [
|
||||
{
|
||||
title: 'Latest',
|
||||
docs: 'https://docs.rsshub.app/programming.html#distill',
|
||||
source: ['/'],
|
||||
target: '/distill',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
3
lib/v2/distill/router.js
Normal file
3
lib/v2/distill/router.js
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/', require('./index'));
|
||||
};
|
||||
Reference in New Issue
Block a user