-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add route for Society journals (#17899)
* Sociology Studies Jounal * Sociology Stuides Journal * delete error description * fix category name * Add router for society issues * fix routes according to docs --------- Co-authored-by: CNYoki <[email protected]>
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Route } from '@/types'; | ||
import got from '@/utils/got'; | ||
import { load } from 'cheerio'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
|
||
export const route: Route = { | ||
path: '/journals/society/current', | ||
categories: ['journal'], | ||
example: '/journals/society/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 pubDateText = $('.dqtab .njq') | ||
.text() | ||
.match(/刊出日期:(\d{4}-\d{2}-\d{2})/); | ||
const pubDate = pubDateText ? parseDate(pubDateText[1]) : null; | ||
|
||
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 abstract = $item.find('div[id^="Abstract"]').text().trim(); | ||
|
||
if (titles && links) { | ||
return { | ||
title: titles, | ||
link: links, | ||
description: abstract, | ||
author: authors, | ||
pubDate, | ||
}; | ||
} | ||
return null; | ||
}) | ||
.filter((item) => item !== null); | ||
|
||
return { | ||
title: '《社会》当期目录', | ||
link: url, | ||
item: items, | ||
}; | ||
} |