From 437fb82858deb4dbf817df1d6960941c27174f81 Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Sun, 29 May 2022 07:23:05 +0800 Subject: [PATCH] feat(route): add Caa.reviews (#9842) * feat(route): add Caa.reviews * Update docs/en/journal.md Co-authored-by: Tony * Update docs/en/journal.md Co-authored-by: Tony * Update docs/journal.md Co-authored-by: Tony * Update lib/v2/caareviews/book.js Co-authored-by: Tony * Update lib/v2/caareviews/essay.js Co-authored-by: Tony * Update lib/v2/caareviews/exhibition.js Co-authored-by: Tony * Update lib/v2/caareviews/radar.js Co-authored-by: Tony * fix(route): add doi Co-authored-by: Tony --- docs/en/journal.md | 13 +++++++ docs/journal.md | 14 ++++++++ lib/v2/caareviews/book.js | 14 ++++++++ lib/v2/caareviews/essay.js | 14 ++++++++ lib/v2/caareviews/exhibition.js | 14 ++++++++ lib/v2/caareviews/maintainer.js | 5 +++ lib/v2/caareviews/radar.js | 25 ++++++++++++++ lib/v2/caareviews/router.js | 5 +++ lib/v2/caareviews/templates/utils.art | 2 ++ lib/v2/caareviews/utils.js | 49 +++++++++++++++++++++++++++ 10 files changed, 155 insertions(+) create mode 100644 lib/v2/caareviews/book.js create mode 100644 lib/v2/caareviews/essay.js create mode 100644 lib/v2/caareviews/exhibition.js create mode 100644 lib/v2/caareviews/maintainer.js create mode 100644 lib/v2/caareviews/radar.js create mode 100644 lib/v2/caareviews/router.js create mode 100644 lib/v2/caareviews/templates/utils.art create mode 100644 lib/v2/caareviews/utils.js diff --git a/docs/en/journal.md b/docs/en/journal.md index 4e5048203..842edd85d 100644 --- a/docs/en/journal.md +++ b/docs/en/journal.md @@ -45,6 +45,19 @@ Fill in parameter `query` with content after `http://export.arxiv.org/api/query? +## caa.reviews + +### Book Reviews + + + +### Exhibition Reviews + + + +### Essays + + ## Cell Journal diff --git a/docs/journal.md b/docs/journal.md index 9bb41c3dc..a2e38a50d 100644 --- a/docs/journal.md +++ b/docs/journal.md @@ -45,6 +45,20 @@ pageClass: routes +## caa.reviews + +### Book Reviews + + + +### Exhibition Reviews + + + +### Essays + + + ## Cell ### 主刊 diff --git a/lib/v2/caareviews/book.js b/lib/v2/caareviews/book.js new file mode 100644 index 000000000..50901a68d --- /dev/null +++ b/lib/v2/caareviews/book.js @@ -0,0 +1,14 @@ +const { rootUrl, getList, getItems } = require('./utils'); + +module.exports = async (ctx) => { + const url = `${rootUrl}/reviews/book`; + + const list = await getList(url); + const items = await getItems(ctx, list); + + ctx.state.data = { + title: 'Book Reviews', + link: url, + item: items, + }; +}; diff --git a/lib/v2/caareviews/essay.js b/lib/v2/caareviews/essay.js new file mode 100644 index 000000000..67b3768a7 --- /dev/null +++ b/lib/v2/caareviews/essay.js @@ -0,0 +1,14 @@ +const { rootUrl, getList, getItems } = require('./utils'); + +module.exports = async (ctx) => { + const url = `${rootUrl}/reviews/essay`; + + const list = await getList(url); + const items = await getItems(ctx, list); + + ctx.state.data = { + title: 'Essays', + link: url, + item: items, + }; +}; diff --git a/lib/v2/caareviews/exhibition.js b/lib/v2/caareviews/exhibition.js new file mode 100644 index 000000000..df9823a52 --- /dev/null +++ b/lib/v2/caareviews/exhibition.js @@ -0,0 +1,14 @@ +const { rootUrl, getList, getItems } = require('./utils'); + +module.exports = async (ctx) => { + const url = `${rootUrl}/reviews/exhibition`; + + const list = await getList(url); + const items = await getItems(ctx, list); + + ctx.state.data = { + title: 'Exhibition Reviews', + link: url, + item: items, + }; +}; diff --git a/lib/v2/caareviews/maintainer.js b/lib/v2/caareviews/maintainer.js new file mode 100644 index 000000000..bbf9a50c6 --- /dev/null +++ b/lib/v2/caareviews/maintainer.js @@ -0,0 +1,5 @@ +module.exports = { + '/book': ['Fatpandac'], + '/essay': ['Fatpandac'], + '/exhibition': ['Fatpandac'], +}; diff --git a/lib/v2/caareviews/radar.js b/lib/v2/caareviews/radar.js new file mode 100644 index 000000000..ca6b8beb2 --- /dev/null +++ b/lib/v2/caareviews/radar.js @@ -0,0 +1,25 @@ +module.exports = { + 'caareviews.org': { + _name: 'caa.reviews', + '.': [ + { + title: 'Book Reviews', + docs: 'https://docs.rsshub.app/journal.html#caa-reviews', + source: ['/reviews/book'], + target: '/caareviews/book', + }, + { + title: 'Exhibition Reviews', + docs: 'https://docs.rsshub.app/journal.html#caa-reviews', + source: ['/reviews/exhibition'], + target: '/caareviews/exhibition', + }, + { + title: 'Essays', + docs: 'https://docs.rsshub.app/journal.html#caa-reviews', + source: ['/reviews/essay'], + target: '/caareviews/essay', + }, + ], + }, +}; diff --git a/lib/v2/caareviews/router.js b/lib/v2/caareviews/router.js new file mode 100644 index 000000000..41b9042d8 --- /dev/null +++ b/lib/v2/caareviews/router.js @@ -0,0 +1,5 @@ +module.exports = function (router) { + router.get('/book', require('./book')); + router.get('/essay', require('./essay')); + router.get('/exhibition', require('./exhibition')); +}; diff --git a/lib/v2/caareviews/templates/utils.art b/lib/v2/caareviews/templates/utils.art new file mode 100644 index 000000000..ae6f69496 --- /dev/null +++ b/lib/v2/caareviews/templates/utils.art @@ -0,0 +1,2 @@ + +{{@ content}} diff --git a/lib/v2/caareviews/utils.js b/lib/v2/caareviews/utils.js new file mode 100644 index 000000000..2fd12d524 --- /dev/null +++ b/lib/v2/caareviews/utils.js @@ -0,0 +1,49 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +const rootUrl = 'http://www.caareviews.org'; + +const getList = async (url) => { + const response = await got(url); + const $ = cheerio.load(response.data); + const list = $('#infinite-content > div') + .map((_index, item) => ({ + title: $(item).find('div.title').text().trim(), + link: new URL($(item).find('div.title > em > a').attr('href'), rootUrl).href, + author: $(item).find('div.contributors').text().trim(), + })) + .get(); + + return list; +}; + +const getItems = async (ctx, list) => + await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const $ = cheerio.load(detailResponse.data); + + const coverUrl = new URL($('div.cover > a').attr('href'), rootUrl).href; + const content = $('div.content.full-review').html(); + item.description = art(path.join(__dirname, 'templates/utils.art'), { + coverUrl, + content, + }); + $('div.review_heading').remove(); + item.pubDate = parseDate($('div.header-text > div.clearfix').text()); + item.doi = $('div.crossref > a').attr('href').replace('http://dx.doi.org/', ''); + + return item; + }) + ) + ); + +module.exports = { + rootUrl, + getList, + getItems, +};