From c2c8b25c80e3b3617fbaab9581d5048c97143520 Mon Sep 17 00:00:00 2001 From: Jianjun Xiao <63627218+etShaw-zh@users.noreply.github.com> Date: Thu, 9 Jan 2025 02:40:00 +0800 Subject: [PATCH] feat(route): Add feed for sciencedirect call for paper (#18039) * add feed for sciencedirect call for paper * Update lib/routes/sciencedirect/call-for-paper.ts Co-authored-by: Tony * add parameters and use templates * Update call-for-paper.ts --------- --- lib/routes/sciencedirect/call-for-paper.ts | 80 +++++++++++++++++++ .../sciencedirect/templates/description.art | 5 ++ 2 files changed, 85 insertions(+) create mode 100644 lib/routes/sciencedirect/call-for-paper.ts create mode 100644 lib/routes/sciencedirect/templates/description.art diff --git a/lib/routes/sciencedirect/call-for-paper.ts b/lib/routes/sciencedirect/call-for-paper.ts new file mode 100644 index 00000000000000..b63e0df9cff6d3 --- /dev/null +++ b/lib/routes/sciencedirect/call-for-paper.ts @@ -0,0 +1,80 @@ +import { Route } from '@/types'; +import { getCurrentPath } from '@/utils/helpers'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { art } from '@/utils/render'; +import path from 'node:path'; +const __dirname = getCurrentPath(import.meta.url); + +export const route: Route = { + path: '/call-for-paper/:subject', + categories: ['journal'], + example: '/sciencedirect/call-for-paper/education', + parameters: { + subject: '学科分类,例如“education”', + }, + radar: [ + { + source: ['sciencedirect.com'], + }, + ], + name: 'Call for Papers', + maintainers: ['etShaw-zh'], + handler, + url: 'sciencedirect.com/browse/calls-for-papers', + description: '`sciencedirect.com/browse/calls-for-papers?subject=education` -> `/sciencedirect/call-for-paper/education`', +}; + +async function handler(ctx) { + const { subject = '' } = ctx.req.param(); + const apiUrl = `https://www.sciencedirect.com/browse/calls-for-papers?subject=${subject}`; + const headers = { + accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', + 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36', // need this to avoid 403, 503 error + }; + const response = await got(apiUrl, { headers }); + const $ = load(response.body); + + const scriptJSON = $('script[data-iso-key="_0"]').text(); + if (!scriptJSON) { + throw new Error('Cannot find the script with data-iso-key="_0"'); + } + + let data; + try { + data = JSON.parse(JSON.parse(scriptJSON)); + } catch (error: any) { + throw new Error(`Failed to parse embedded script JSON: ${error.message}`); + } + + const cfpList = data?.callsForPapers?.list || []; + if (!cfpList.length) { + throw new Error('No Calls for Papers found'); + } + + const items = cfpList.map((cfp) => { + const link = `https://www.sciencedirect.com/special-issue/${cfp.contentId}/${cfp.url}`; + const description = art(path.join(__dirname, 'templates/description.art'), { + summary: cfp.summary, + submissionDeadline: cfp.submissionDeadline, + displayName: cfp.journal.displayName, + impactFactor: cfp.journal.impactFactor, + citeScore: cfp.journal.citeScore, + }); + + return { + title: cfp.title, + author: `${cfp.journal.displayName} (IF: ${cfp.journal.impactFactor})`, + link, + description, + pubDate: cfp.submissionDeadline || '', + }; + }); + + return { + title: `ScienceDirect Calls for Papers - ${subject}`, + link: apiUrl, + description: `Calls for Papers on ScienceDirect for subject: ${subject}`, + item: items, + }; +} diff --git a/lib/routes/sciencedirect/templates/description.art b/lib/routes/sciencedirect/templates/description.art new file mode 100644 index 00000000000000..d1ecbf0ab98a00 --- /dev/null +++ b/lib/routes/sciencedirect/templates/description.art @@ -0,0 +1,5 @@ +
+

Summary: {{summary}}

+

Submission Deadline: {{submissionDeadline}}

+

Journal: {{displayName}} (IF: {{impactFactor}}, CiteScore: {{citeScore}})

+