feat(route): add Research Gate Publications (#7544)

This commit is contained in:
Ethan Shen
2021-11-27 14:29:30 +08:00
committed by GitHub
parent a43b67bc1f
commit e48858d59f
4 changed files with 75 additions and 0 deletions

View File

@@ -372,6 +372,12 @@ Compared to the official one, this feed:
</RouteEn> </RouteEn>
## Research Gate
### Publications
<RouteEn author="nczitzk" example="/researchgate/publications/Somsak-Panha" path="/researchgate/publications/:username" :paramsDesc="['Username, can be found in URL']"/>
## Semiconductor Industry Association ## Semiconductor Industry Association
### Latest News ### Latest News

View File

@@ -633,6 +633,12 @@ IPFS 网关有可能失效,那时候换成其他网关。
</Route> </Route>
## Research Gate
### Publications
<Route author="nczitzk" example="/researchgate/publications/Somsak-Panha" path="/researchgate/publications/:username" :paramsDesc="['用户名,可在用户页地址栏中找到']"/>
## Simons Foundation ## Simons Foundation
### 文章 ### 文章

View File

@@ -4212,4 +4212,7 @@ router.get('/s-hentai/:id?', lazyloadRouteHandler('./routes/s-hentai'));
// Deprecated: DO NOT ADD ROUTE HERE // Deprecated: DO NOT ADD ROUTE HERE
// Research Gate
router.get('/researchgate/publications/:id', require('./routes/researchgate/publications'));
module.exports = router; module.exports = router;

View File

@@ -0,0 +1,60 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id;
const rootUrl = 'https://www.researchgate.net';
const currentUrl = `${rootUrl}/profile/${id}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('div[itemprop="headline"] a')
.slice(0, 15)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.doi = content('meta[property="citation_doi"]').attr('content');
item.pubDate = Date.parse(content('meta[property="citation_publication_date"]').attr('content'));
const authors = [];
content('meta[property="citation_author"]').each(function () {
authors.push(content(this).attr('content'));
});
item.author = authors.join(', ');
item.description = content('div[itemprop="description"]').html();
return item;
})
)
);
ctx.state.data = {
title: `${$('meta[property="profile:username"]').attr('content')}'s Publications - ResearchGate`,
link: currentUrl,
item: items,
};
};