feat(route): MDPI(journal) (#10017)

* feat(route): add mdpi

* feat(docs): add mdpi
This commit is contained in:
Derek
2022-06-23 21:39:57 +08:00
committed by GitHub
parent f41f695c91
commit 47640860ba
7 changed files with 104 additions and 0 deletions
+6
View File
@@ -140,6 +140,12 @@ The parameter id in the route is the id in the URL of the user's Google Scholar
<RouteEn author="Fatpandac" example="/informs/mnsc" path="/informs/:category?" :paramsDesc="['Category, can be found in the url of the page, `orsc` by default']"/>
## MDPI
### Journal
<RouteEn author="Derekmini" example="/mdpi/analytica" path="/mdpi/:journal" :paramsDesc="['Journal Name, get it from the journal homepage']" radar="1" rssbud="1"/>
## MIT Technology Review
<RouteEn author="zphw" example="/technologyreview" path="/technologyreview" />
+6
View File
@@ -134,6 +134,12 @@ pageClass: routes
<Route author="Fatpandac" example="/informs/mnsc" path="/informs/:category?" :paramsDesc="['类型, 可以在 url 中得到,默认为 `orsc`']"/>
## MDPI
### 期刊
<Route author="Derekmini" example="/mdpi/analytica" path="/mdpi/:journal" :paramsDesc="['期刊名称,从期刊主页 URL 中获得']" radar="1" rssbud="1"/>
## Nature 系列
::: tip Tips
+61
View File
@@ -0,0 +1,61 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const path = require('path');
const { art } = require('@/utils/render');
const { CookieJar } = require('tough-cookie');
const cookieJar = new CookieJar();
module.exports = async (ctx) => {
const journal = ctx.params.journal;
const host = 'https://www.mdpi.com';
const jrnlUrl = `${host}/journal/${journal}`;
const response = await got(jrnlUrl, {
cookieJar,
});
const $ = cheerio.load(response.data);
const jrnlName = $('.journal__description').find('h1').text();
const issueUrl = `${host}${$('.side-menu-ul').find('a').eq(1).attr('href')}`;
const response2 = await got(issueUrl, {
cookieJar,
});
const $2 = cheerio.load(response2.data);
const issue = $2('.content__container').find('h1').text().trim();
const list = $2('.article-item')
.map((_, item) => {
const title = $2(item).find('.title-link').text();
const link = `${host}${$2(item).find('.title-link').attr('href')}`;
const authors = $2(item).find('.authors').find('.inlineblock').text();
const doi = $2(item).find('.color-grey-dark').find('a').attr('href').replace('https://doi.org/', '');
$2(item).find('.abstract-full').find('a').remove();
const abstract = $2(item).find('.abstract-full').text().trim();
const img = `${host}${$2(item).find('.openpopupgallery').find('img').attr('data-src')}`;
return {
title,
authors,
link,
doi,
abstract,
issue,
img,
};
})
.get();
const renderDesc = (item) =>
art(path.join(__dirname, 'templates/description.art'), {
item,
});
const items = list.map((item) => {
item.description = renderDesc(item);
return item;
});
ctx.state.data = {
title: jrnlName,
link: jrnlUrl,
item: items,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/:journal': ['Derekmini'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'mdpi.com': {
_name: 'MDPI',
www: [
{
title: 'Journal',
docs: 'https://docs.rsshub.app/journal.html#MDPI',
source: '/journal/:journal',
target: '/mdpi/:journal',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:journal', require('./journal'));
};
+12
View File
@@ -0,0 +1,12 @@
<p>
<span><big>{{ item.title }}</big></span><br>
</p>
<p>
<span><small><i>{{ item.authors }}</i></small></span><br>
<span><small><i>https://doi.org/{{ item.doi }}</i></small></span><br>
<span><small><i>{{ item.issue }}</i></small></span><br>
<img src={{ item.img }}>
</p>
<p>
<span>{{ item.abstract }}</span><br>
</p>