diff --git a/lib/routes/zongheng/detail.ts b/lib/routes/zongheng/detail.ts new file mode 100644 index 000000000..aa05b7c33 --- /dev/null +++ b/lib/routes/zongheng/detail.ts @@ -0,0 +1,77 @@ +import { DataItem, Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; + +export const route: Route = { + path: '/detail/:id', + categories: ['reading'], + example: '/zongheng/detail/1366535', + parameters: { id: '作品 ID' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['www.zongheng.org/detail/:id'], + }, + ], + name: '章节更新', + maintainers: ['TonyRL'], + handler, + url: 'www.zongheng.com', +}; + +async function handler(ctx) { + const { id } = ctx.req.param(); + + const link = `https://www.zongheng.com/detail/${id}`; + const pageResponse = await ofetch(link); + const $ = load(pageResponse); + + const description = JSON.parse( + $('script:contains("window.__NUXT__")') + .text() + .match(/description:(.*?),totalWords/)?.[1] || '""' + ).replaceAll('
', ' '); + const category = $('.book-info--tags span') + .toArray() + .map((tag) => $(tag).text().trim()); + const author = $('.author-info--name').text().trim(); + + const apiReponse = await ofetch('https://bookapi.zongheng.com/api/chapter/getChapterList', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: new URLSearchParams({ + bookId: id, + }), + }); + + const items: DataItem[] = apiReponse.result.chapterList.flatMap((list) => + list.chapterViewList.map((chapter) => ({ + title: `${list.tome.tomeName ? `${list.tome.tomeName} - ` : ''}${chapter.chapterName}`, + link: `https://read.zongheng.com/chapter/${id}/${chapter.chapterId}.html`, + pubDate: timezone(parseDate(chapter.createTime), 8), + guid: `zongheng:${id}:${list.tome.tomeId}:${chapter.chapterId}`, + author, + category, + })) + ); + + return { + title: `${$('.book-info--title span').text()}(${author})- 纵横中文网`, + description: `${$('.book-info--nums').text().trim()} ${description}`, + link, + allowEmpty: true, + image: $('.book-info--coverImage-img').attr('src'), + item: items, + }; +} diff --git a/lib/routes/zongheng/namespace.ts b/lib/routes/zongheng/namespace.ts new file mode 100644 index 000000000..f7a96067b --- /dev/null +++ b/lib/routes/zongheng/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '纵横中文网', + url: 'www.zongheng.com', + lang: 'zh-CN', +};