-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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 journal《回归线》 (#15991)
* add a new route: arktca/posts * fix a small description error in Route * using cache * new arknights folder in hypergryph and put all about arknights in it * adjust the radar rule * adjust variable name to camelCase,use template literals,fix cache problem * change variable name to camelCase * adjust code format,now cache doesn't use same element * fix the guid and link use const string
- Loading branch information
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
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,124 @@ | ||
import { Route } from '@/types'; | ||
import got from '@/utils/got'; | ||
import { load } from 'cheerio'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import cache from '@/utils/cache'; | ||
|
||
const rssDescription = '期刊《回归线》 | 泰拉创作者联合会'; | ||
const url = 'aneot.arktca.com'; | ||
const author = 'Bendancom'; | ||
|
||
export const route: Route = { | ||
path: '/arknights/arktca', | ||
categories: ['game'], | ||
example: '/hypergryph/arknights/arktca', | ||
parameters: {}, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
name: '期刊', | ||
url, | ||
maintainers: [author], | ||
radar: [ | ||
{ | ||
source: [url], | ||
}, | ||
], | ||
description: rssDescription, | ||
handler, | ||
}; | ||
|
||
async function handler() { | ||
const baseUrl = `https://${url}`; | ||
const { data: allResponse } = await got(`${baseUrl}/posts`); | ||
const $ = load(allResponse); | ||
|
||
const allUrlList = $('div.theme-hope-content > table') | ||
.find('a') | ||
.toArray() | ||
.map((item) => baseUrl + $(item).prop('href')); | ||
|
||
const journalList = await Promise.all( | ||
allUrlList.map(async (item) => { | ||
const { data: response } = await got(item); | ||
const $$ = load(response); | ||
const regVol = /(?<=Vol. )(\w+)/; | ||
const match = regVol.exec($$('div.vp-page-title').find('h1').text()); | ||
const volume = match ? match[0] : ''; | ||
const links = $$('div.theme-hope-content > ul a') | ||
.toArray() | ||
.map((e) => baseUrl + $(e).prop('href')); | ||
return { | ||
volume, | ||
links, | ||
}; | ||
}) | ||
); | ||
|
||
const journals = await Promise.all( | ||
journalList.map( | ||
async (item) => | ||
await Promise.all( | ||
item.links.map((link) => | ||
cache.tryGet(link, async () => { | ||
const { data: response } = await got(link); | ||
const $$ = load(response); | ||
|
||
$$('div.ads-container').remove(); | ||
const language = $$('html').prop('lang'); | ||
|
||
const pageTitle = $$('div.vp-page-title'); | ||
|
||
const title = `Vol.${item.volume} ` + pageTitle.children('h1').text(); | ||
const pageInfo = pageTitle.children('div.page-info'); | ||
|
||
const pageAuthorInfo = pageInfo.children('span.page-author-info'); | ||
const author = pageAuthorInfo.find('span.page-author-item').text(); | ||
|
||
const pageDateInfo = pageInfo.children('span.page-date-info'); | ||
const date = pageDateInfo.children('meta').prop('content'); | ||
const pubDate = parseDate(date); | ||
|
||
const pageCategoryInfo = pageInfo.find('span.page-category-info'); | ||
const category = pageCategoryInfo.children('meta').prop('content'); | ||
|
||
const article = $$('div.theme-hope-content'); | ||
const description = article.html(); | ||
|
||
const comments = Number.parseInt($$('span.wl-num').text()); | ||
return { | ||
title, | ||
language, | ||
author, | ||
pubDate, | ||
category, | ||
description, | ||
comments, | ||
guid: link, | ||
link, | ||
}; | ||
}) | ||
) | ||
) | ||
) | ||
); | ||
|
||
const logoUrl = `${baseUrl}/logo.svg`; | ||
|
||
return { | ||
title: '回归线', | ||
link: baseUrl, | ||
description: rssDescription, | ||
icon: logoUrl, | ||
logo: logoUrl, | ||
image: logoUrl, | ||
author, | ||
language: 'zh-CN', | ||
item: journals.flat(Infinity), | ||
}; | ||
} |
File renamed without changes.
File renamed without changes.