feat(route): add Distill (#8491)

This commit is contained in:
Ethan Shen
2021-11-27 16:54:24 +08:00
committed by GitHub
parent 9cfd31496e
commit ef2f74d08e
6 changed files with 95 additions and 0 deletions

View File

@@ -16,6 +16,12 @@ pageClass: routes
<RouteEn author="fengkx" example="/cve/search/PostgreSQL" path="/cve/search/:keyword" :paramsDesc="['keyword']" /> <RouteEn author="fengkx" example="/cve/search/PostgreSQL" path="/cve/search/:keyword" :paramsDesc="['keyword']" />
## Distill
### Latest
<RouteEn author="nczitzk" example="/distill" path="/distill"/>
## GitHub ## GitHub
::: tip ::: tip

View File

@@ -58,6 +58,12 @@ pageClass: routes
<Route author="nczitzk" example="/deeplearningai/thebatch" path="/deeplearningai/thebatch"/> <Route author="nczitzk" example="/deeplearningai/thebatch" path="/deeplearningai/thebatch"/>
## Distill
### Latest
<Route author="nczitzk" example="/distill" path="/distill"/>
## Dockone ## Dockone
### 周报 ### 周报

64
lib/v2/distill/index.js Normal file
View 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,
};
};

View File

@@ -0,0 +1,3 @@
module.exports = {
'/': ['nczitzk'],
};

13
lib/v2/distill/radar.js Normal file
View 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
View File

@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/', require('./index'));
};