feat(route): routledge (#13993)

This commit is contained in:
Tony 2023-12-08 13:36:55 +00:00 committed by GitHub
parent 6dd600b098
commit 8ec0902c09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,78 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const { join } = require('path');
module.exports = async (ctx) => {
const { bookName, bookId } = ctx.params;
const baseUrl = 'https://www.routledge.com';
const pageUrl = `${baseUrl}/${bookName}/book-series/${bookId}`;
const { data: response } = await got(pageUrl, {
headers: {
accept: 'text/html, */*; q=0.01',
},
searchParams: {
publishedFilter: 'alltitles',
pd: 'published,forthcoming',
pg: 1,
pp: 12,
so: 'pub',
view: 'list',
},
});
const $ = cheerio.load(response);
const list = $('.row.book')
.toArray()
.map((item) => {
item = $(item);
const title = item.find('h3 a');
const description = item.find('p.description');
const meta = item.find('p.description').prev().text().split('\n');
return {
title: title.text(),
link: title.attr('href'),
description: description.text(),
pubDate: parseDate(meta.pop().trim(), 'MMMM DD, YYYY'),
author: meta
.map((i) => i.trim())
.filter((i) => i)
.join(', '),
};
});
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data } = await got(item.link);
const $ = cheerio.load(data);
const isbn = $('meta[property="books:isbn"]').attr('content');
const { data: image } = await got('https://productimages.routledge.com', {
searchParams: {
isbn,
size: 'amazon',
ext: 'jpg',
},
});
const description = $('.sticky-div');
description.find('button.accordion-button').contents().unwrap();
description.find('.fa-shopping-cart').parent().parent().remove();
item.description = art(join(__dirname, 'templates/description.art'), {
image,
description: description.html(),
});
return item;
})
)
);
ctx.state.data = {
title: $('head title').text(),
description: $('head meta[name="description"]').attr('content'),
link: pageUrl,
item: items,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/:bookName/book-series/:bookId': ['TonyRL'],
};

13
lib/v2/routledge/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'routledge.com': {
_name: 'Routledge',
'.': [
{
title: 'Book Series',
docs: 'https://docs.rsshub.app/routes/journals#routledge',
source: ['/:bookName/book-series/:bookId'],
target: '/routledge/:bookName/book-series/:bookId',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:bookName/book-series/:bookId', require('./book-series'));
};

View File

@ -0,0 +1,7 @@
{{ if image }}
<img src="{{ image }}"><br>
{{ /if }}
{{ if description }}
{{@ description }}
{{ /if }}

View File

@ -411,6 +411,12 @@ In `https://pubmed.ncbi.nlm.nih.gov/trending/?filter=simsearch1.fha&filter=pubt.
</Route>
## Routledge {#routledge}
### Book Series {#routledge-book-series}
<Route author="TonyRL" example="/routledge/:bookName/book-series/:bookId" path="/routledge/A-Colour-Atlas/book-series/CRCACOLOATLA" paramsDesc={['Book name, can be found in URL', 'Book ID, can be found in URL']} radar="1" />
## Royal Society of Chemistry {#royal-society-of-chemistry}
### Journal {#royal-society-of-chemistry-journal}