Skip to content

Commit

Permalink
feat(route): uchicago journals (DIYgod#11944)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored and nullqwertyuiop committed Mar 1, 2023
1 parent bf02486 commit e46024a
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/en/journal.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ Including 'Science', 'Science Advances', 'Science Immunology', 'Science Robotics

<RouteEn author="Derekmini TonyRL" example="/springer/journal/10450" path="/springer/journal/:journal" :paramsDesc="['Journal Code, the number in the URL from the journal homepage']" radar="1" rssbud="1"/>

## The University of Chicago Press: Journals

### Current Issue

<RouteEn author="TonyRL" example="/uchicago/journals/current/jpe" path="/uchicago/journals/current/:journal" :paramsDesc="['Journal id, can be found in URL. [Browse journals by title](https://www.journals.uchicago.edu/action/showPublications)']" radar="1"/>

## USENIX

### Security Symposia
Expand Down
80 changes: 80 additions & 0 deletions lib/v2/uchicago/current.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { getCookies, setCookies } = require('@/utils/puppeteer-utils');
const logger = require('@/utils/logger');

module.exports = async (ctx) => {
const { journal } = ctx.params;
const baseUrl = 'https://www.journals.uchicago.edu';
const link = `${baseUrl}/toc/${journal}/current`;

const browser = await require('@/utils/puppeteer')();
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', (request) => {
request.resourceType() === 'document' ? request.continue() : request.abort();
});
logger.debug(`Requesting ${link}`);
await page.goto(link, {
waitUntil: 'domcontentloaded',
});
const response = await page.evaluate(() => document.documentElement.innerHTML);
const cookies = await getCookies(page);
page.close();
const $ = cheerio.load(response);

const list = $('.issue-item__title')
.toArray()
.map((item) => ({ link: `${baseUrl}${$(item).find('a').attr('href')}` }));

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const page = await browser.newPage();
await setCookies(page, cookies, 'journals.uchicago.edu');
await page.setRequestInterception(true);
page.on('request', (request) => {
request.resourceType() === 'document' ? request.continue() : request.abort();
});
logger.debug(`Requesting ${item.link}`);
await page.goto(item.link, {
waitUntil: 'domcontentloaded',
referer: link,
});
const response = await page.evaluate(() => document.documentElement.innerHTML);
page.close();

const $ = cheerio.load(response);

item.title = $('head title').text();
item.pubDate = parseDate($('head meta[name="dc.Date"]').attr('content'));
item.doi = $('head meta[scheme="doi"]').attr('content');
item.author = $('.author-name span')
.toArray()
.map((author) => $(author).text())
.join(', ');

$('.figure__image').each((_, elem) => {
if (elem.attribs['data-lg-src']) {
$(elem).attr('src', `${baseUrl}${elem.attribs['data-lg-src']}`);
delete elem.attribs['data-lg-src'];
}
});

item.description = $('.article__body').html();

return item;
})
)
);

browser.close();

ctx.state.data = {
title: $('head title').text(),
description: $('.jumbotron-journal-info').text(),
link,
image: $('head meta[property="og:image"]').attr('content'),
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/uchicago/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/journals/current/:journal': ['TonyRL'],
};
13 changes: 13 additions & 0 deletions lib/v2/uchicago/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'journals.uchicago.edu': {
_name: 'The University of Chicago Press: Journals',
'.': [
{
title: 'Current Issue',
docs: 'https://docs.rsshub.app/journal.html#the-university-of-chicago-press-journals',
source: ['/toc/:journal/current', '/journal/:journal'],
target: '/uchicago/journals/current/:journal',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/uchicago/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/journals/current/:journal', require('./current'));
};

0 comments on commit e46024a

Please sign in to comment.