From 8da57e9fff3a943e3d8c1ae20159fab60f21a932 Mon Sep 17 00:00:00 2001 From: CNYoki Date: Thu, 21 Nov 2024 13:56:52 +0800 Subject: [PATCH 1/6] Sociology Studies Jounal --- lib/routes/ajcass/namespace.ts | 10 ++++ lib/routes/ajcass/shxyj.ts | 87 ++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 lib/routes/ajcass/namespace.ts create mode 100644 lib/routes/ajcass/shxyj.ts diff --git a/lib/routes/ajcass/namespace.ts b/lib/routes/ajcass/namespace.ts new file mode 100644 index 00000000000000..a15e846d5e79b6 --- /dev/null +++ b/lib/routes/ajcass/namespace.ts @@ -0,0 +1,10 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '社科期刊网', + url: 'ajcass.com', + description: '中国社会科学院学术期刊方阵', + zh: { + name: '社科期刊网', + }, +}; diff --git a/lib/routes/ajcass/shxyj.ts b/lib/routes/ajcass/shxyj.ts new file mode 100644 index 00000000000000..ce6218559d7b70 --- /dev/null +++ b/lib/routes/ajcass/shxyj.ts @@ -0,0 +1,87 @@ +import { Route } from '@/types'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/shxyj/:year?/:issue?', + categories: ['academic'], + example: '/ajcass/shxyj/2024/1', + parameters: { + year: { + type: 'string', + description: 'Year of the issue', + optional: true, + }, + issue: { + type: 'string', + description: 'Issue number', + optional: true, + }, + }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '社会学研究', + maintainers: ['CNYoki'], + handler, +}; + +async function handler(ctx) { + let { year, issue } = ctx.req.param(); + + if (!year) { + // 获取最新一期的 year 和 issue + const response = await got('https://shxyj.ajcass.com/'); + const $ = load(response.body); + const latestIssueText = $('p.hod.pop').first().text(); + + const match = latestIssueText.match(/(\d{4}) Vol\.(\d+):/); + if (match) { + year = match[1]; + issue = match[2]; + } else { + throw new Error('无法获取最新的 year 和 issue'); + } + } + + const url = `https://shxyj.ajcass.com/Magazine/?Year=${year}&Issue=${issue}`; + const response = await got(url); + const $ = load(response.body); + + const items = $('#tab tr') + .map((_, item) => { + const $item = $(item); + const articleTitle = $item.find('a').first().text().trim(); + const articleLink = $item.find('a').first().attr('href'); + const summary = $item.find('li').eq(1).text().replace('[摘要]', '').trim(); + const authors = $item.find('li').eq(2).text().replace('作者:', '').trim(); + const pubDate = parseDate(`${year}-${Number.parseInt(issue) * 2}`); + + if (articleTitle && articleLink) { + return { + title: articleTitle, + link: `https://shxyj.ajcass.com${articleLink}`, + description: summary, + author: authors, + pubDate, + }; + } + return null; // 确保在所有情况下都有返回值 + }) + .toArray(); + + // eslint-disable-next-line no-console + console.log('items:', JSON.stringify(items, null, 2)); + + return { + title: `社会学研究 ${year}年第${issue}期`, + link: url, + item: items, + }; +} From 53ee40a7f5dee35081e7152477f7132f15ce3199 Mon Sep 17 00:00:00 2001 From: CNYoki Date: Thu, 21 Nov 2024 14:07:42 +0800 Subject: [PATCH 2/6] Sociology Stuides Journal --- lib/routes/ajcass/shxyj.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/routes/ajcass/shxyj.ts b/lib/routes/ajcass/shxyj.ts index ce6218559d7b70..4392d9a3652c02 100644 --- a/lib/routes/ajcass/shxyj.ts +++ b/lib/routes/ajcass/shxyj.ts @@ -36,7 +36,6 @@ async function handler(ctx) { let { year, issue } = ctx.req.param(); if (!year) { - // 获取最新一期的 year 和 issue const response = await got('https://shxyj.ajcass.com/'); const $ = load(response.body); const latestIssueText = $('p.hod.pop').first().text(); @@ -55,7 +54,8 @@ async function handler(ctx) { const $ = load(response.body); const items = $('#tab tr') - .map((_, item) => { + .toArray() + .map((item) => { const $item = $(item); const articleTitle = $item.find('a').first().text().trim(); const articleLink = $item.find('a').first().attr('href'); @@ -72,12 +72,9 @@ async function handler(ctx) { pubDate, }; } - return null; // 确保在所有情况下都有返回值 + return null; }) - .toArray(); - - // eslint-disable-next-line no-console - console.log('items:', JSON.stringify(items, null, 2)); + .filter((item) => item !== null); return { title: `社会学研究 ${year}年第${issue}期`, From 63fbf7ea99b2b115a8a4cdaa8dae98edc0aa4ed7 Mon Sep 17 00:00:00 2001 From: CNYoki Date: Fri, 22 Nov 2024 10:18:46 +0800 Subject: [PATCH 3/6] delete error description --- lib/routes/ajcass/namespace.ts | 1 + lib/routes/ajcass/shxyj.ts | 15 ++------------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/lib/routes/ajcass/namespace.ts b/lib/routes/ajcass/namespace.ts index a15e846d5e79b6..f471eed914ee46 100644 --- a/lib/routes/ajcass/namespace.ts +++ b/lib/routes/ajcass/namespace.ts @@ -4,6 +4,7 @@ export const namespace: Namespace = { name: '社科期刊网', url: 'ajcass.com', description: '中国社会科学院学术期刊方阵', + lang: 'zh-CN', zh: { name: '社科期刊网', }, diff --git a/lib/routes/ajcass/shxyj.ts b/lib/routes/ajcass/shxyj.ts index 4392d9a3652c02..ff6945afe4f8df 100644 --- a/lib/routes/ajcass/shxyj.ts +++ b/lib/routes/ajcass/shxyj.ts @@ -5,20 +5,9 @@ import { parseDate } from '@/utils/parse-date'; export const route: Route = { path: '/shxyj/:year?/:issue?', - categories: ['academic'], + categories: ['Scientific Journal'], example: '/ajcass/shxyj/2024/1', - parameters: { - year: { - type: 'string', - description: 'Year of the issue', - optional: true, - }, - issue: { - type: 'string', - description: 'Issue number', - optional: true, - }, - }, + parameters: { year: 'Year of the issue, `null` for the lastest', issue: 'Issue number, `null` for the lastest' }, features: { requireConfig: false, requirePuppeteer: false, From 17e0a80daf36a23bd9a06cf4ec5153db1b7f0211 Mon Sep 17 00:00:00 2001 From: CNYoki Date: Fri, 22 Nov 2024 10:22:54 +0800 Subject: [PATCH 4/6] fix category name --- lib/routes/ajcass/shxyj.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/ajcass/shxyj.ts b/lib/routes/ajcass/shxyj.ts index ff6945afe4f8df..e4324927d16a2b 100644 --- a/lib/routes/ajcass/shxyj.ts +++ b/lib/routes/ajcass/shxyj.ts @@ -5,7 +5,7 @@ import { parseDate } from '@/utils/parse-date'; export const route: Route = { path: '/shxyj/:year?/:issue?', - categories: ['Scientific Journal'], + categories: ['journal'], example: '/ajcass/shxyj/2024/1', parameters: { year: 'Year of the issue, `null` for the lastest', issue: 'Issue number, `null` for the lastest' }, features: { From a3600d7f26fc8c4e4c0dca6192a1b52b4ffe48cd Mon Sep 17 00:00:00 2001 From: CNYoki Date: Mon, 16 Dec 2024 11:54:26 +0800 Subject: [PATCH 5/6] Add router for society issues --- lib/routes/society/current.ts | 56 +++++++++++++++++++++++++++++++++ lib/routes/society/namespace.ts | 11 +++++++ 2 files changed, 67 insertions(+) create mode 100644 lib/routes/society/current.ts create mode 100644 lib/routes/society/namespace.ts diff --git a/lib/routes/society/current.ts b/lib/routes/society/current.ts new file mode 100644 index 00000000000000..0c3ec0ed23ad5c --- /dev/null +++ b/lib/routes/society/current.ts @@ -0,0 +1,56 @@ +import { Route } from '@/types'; +import got from '@/utils/got'; +import { load } from 'cheerio'; + +export const route: Route = { + path: '/current', + categories: ['journal'], + example: '/current', + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '《社会》期刊当期目录', + maintainers: ['CNYoki'], + handler, +}; + +async function handler() { + const url = `https://www.society.shu.edu.cn/CN/1004-8804/current.shtml`; + const response = await got(url); + const $ = load(response.body); + + const items = $('.wenzhanglanmu') + .nextAll('.noselectrow') + .toArray() + .map((item) => { + const $item = $(item); + const titles = $item.find('.biaoti').text().trim(); + const links = $item.find('.biaoti').attr('href'); + const authors = $item.find('.zuozhe').text().trim(); + const date = $item.find('.kmnjq').text().trim(); + const abstract = $item.find('div[id^="Abstract"]').text().trim(); + + if (titles && links) { + return { + title: titles, + link: links, + description: abstract, + author: authors, + date, + }; + } + return null; + }) + .filter((item) => item !== null); + + return { + title: `《社会》期刊当期目录`, + link: url, + item: items, + }; +} diff --git a/lib/routes/society/namespace.ts b/lib/routes/society/namespace.ts new file mode 100644 index 00000000000000..5bb67020e8ada4 --- /dev/null +++ b/lib/routes/society/namespace.ts @@ -0,0 +1,11 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '《社会》期刊', + url: 'www.society.shu.edu.cn', + description: '《社会》期刊当期目录', + lang: 'zh-CN', + zh: { + name: '《社会》期刊', + }, +}; From 8cd008e29c459179f840134053e290fbf2df5ab0 Mon Sep 17 00:00:00 2001 From: CNYoki Date: Tue, 17 Dec 2024 10:37:06 +0800 Subject: [PATCH 6/6] fix routes according to docs --- .../{society/current.ts => shu/society.ts} | 20 ++++++++++++------- lib/routes/society/namespace.ts | 11 ---------- 2 files changed, 13 insertions(+), 18 deletions(-) rename lib/routes/{society/current.ts => shu/society.ts} (71%) delete mode 100644 lib/routes/society/namespace.ts diff --git a/lib/routes/society/current.ts b/lib/routes/shu/society.ts similarity index 71% rename from lib/routes/society/current.ts rename to lib/routes/shu/society.ts index 0c3ec0ed23ad5c..6da04f7760ad8d 100644 --- a/lib/routes/society/current.ts +++ b/lib/routes/shu/society.ts @@ -1,11 +1,12 @@ import { Route } from '@/types'; import got from '@/utils/got'; import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; export const route: Route = { - path: '/current', + path: '/journals/society/current', categories: ['journal'], - example: '/current', + example: '/journals/society/current', features: { requireConfig: false, requirePuppeteer: false, @@ -14,16 +15,22 @@ export const route: Route = { supportPodcast: false, supportScihub: false, }, - name: '《社会》期刊当期目录', + name: '《社会》杂志当期目录', maintainers: ['CNYoki'], handler, }; async function handler() { - const url = `https://www.society.shu.edu.cn/CN/1004-8804/current.shtml`; + const url = 'https://www.society.shu.edu.cn/CN/1004-8804/current.shtml'; const response = await got(url); const $ = load(response.body); + // 提取刊出日期 + const pubDateText = $('.dqtab .njq') + .text() + .match(/刊出日期:(\d{4}-\d{2}-\d{2})/); + const pubDate = pubDateText ? parseDate(pubDateText[1]) : null; + const items = $('.wenzhanglanmu') .nextAll('.noselectrow') .toArray() @@ -32,7 +39,6 @@ async function handler() { const titles = $item.find('.biaoti').text().trim(); const links = $item.find('.biaoti').attr('href'); const authors = $item.find('.zuozhe').text().trim(); - const date = $item.find('.kmnjq').text().trim(); const abstract = $item.find('div[id^="Abstract"]').text().trim(); if (titles && links) { @@ -41,7 +47,7 @@ async function handler() { link: links, description: abstract, author: authors, - date, + pubDate, }; } return null; @@ -49,7 +55,7 @@ async function handler() { .filter((item) => item !== null); return { - title: `《社会》期刊当期目录`, + title: '《社会》当期目录', link: url, item: items, }; diff --git a/lib/routes/society/namespace.ts b/lib/routes/society/namespace.ts deleted file mode 100644 index 5bb67020e8ada4..00000000000000 --- a/lib/routes/society/namespace.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { Namespace } from '@/types'; - -export const namespace: Namespace = { - name: '《社会》期刊', - url: 'www.society.shu.edu.cn', - description: '《社会》期刊当期目录', - lang: 'zh-CN', - zh: { - name: '《社会》期刊', - }, -};