* chore(deps-dev): bump eslint-plugin-unicorn from 66.0.0 to 68.0.0 Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 66.0.0 to 68.0.0. - [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases) - [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v66.0.0...v68.0.0) --- updated-dependencies: - dependency-name: eslint-plugin-unicorn dependency-version: 68.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * style: fix no-useless-coercion * style: fix prefer-boolean-return * style: fix no-useless-logical-operand * style: fix prefer-single-replace * style: fix consistent-conditional-object-spread * style: fix no-useless-else * style: fix prefer-unicode-code-point-escapes * style: fix operator-assignment * style: fix prefer-continue * style: fix prefer-math-constants * style: fix prefer-hoisting-branch-code * style: fix prefer-array-slice * style: fix consistent-class-member-order * style: fix no-return-array-push * style: fix prefer-promise-with-resolvers * style: fix no-array-concat-in-loop * style: fix no-loop-iterable-mutation * style: fix no-invalid-argument-count * style: fix no-duplicate-if-branches * style: fix prefer-else-if * style: fix no-unreadable-for-of-expression * style: fix logical-assignment-operators * style: fix default-export-style * style: revert false positve in prefer-type-literal-last in #22274 * style: fix arrow-body-style * style: add v68 recommended preset * style: refactor GraphQL queries to use template literals for better readability --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tony <TonyRL@users.noreply.github.com>
91 lines
3.5 KiB
TypeScript
91 lines
3.5 KiB
TypeScript
import { load } from 'cheerio';
|
||
|
||
import type { Data, DataItem, Route } from '@/types';
|
||
import { ViewType } from '@/types';
|
||
import cache from '@/utils/cache';
|
||
import got from '@/utils/got';
|
||
import { parseDate } from '@/utils/parse-date';
|
||
import timezone from '@/utils/timezone';
|
||
|
||
const baseUrl = 'https://www.dora-world.com';
|
||
|
||
export const route: Route = {
|
||
path: '/article/:topic/:topicId?',
|
||
categories: ['anime'],
|
||
view: ViewType.Articles,
|
||
example: '/dora-world/article/contents',
|
||
parameters: {
|
||
topic: 'Topic name, can be found in URL. For example: the topic name of [https://www.dora-world.com/movie](https://www.dora-world.com/movie) is `movie`',
|
||
topicId: 'Topic id, can be found in URL. For example: the topic id of [https://www.dora-world.com/contents?t=197](https://www.dora-world.com/contents?t=197) is `197`',
|
||
},
|
||
features: {
|
||
requireConfig: false,
|
||
requirePuppeteer: false,
|
||
antiCrawler: false,
|
||
supportBT: false,
|
||
supportPodcast: false,
|
||
supportScihub: false,
|
||
},
|
||
radar: [
|
||
{
|
||
source: ['www.dora-world.com/:topic'],
|
||
},
|
||
],
|
||
name: 'Article',
|
||
maintainers: ['AChangAZha'],
|
||
handler,
|
||
};
|
||
|
||
async function handler(ctx): Promise<Data> {
|
||
const { topic, topicId = '' } = ctx.req.param();
|
||
const topicIdParam = topicId === '' ? '' : `?t=${topicId}`;
|
||
const link = `${baseUrl}/${topic}${topicIdParam}`;
|
||
const { data: html } = await got(baseUrl);
|
||
const $ = load(html);
|
||
const nextData = JSON.parse($('script#__NEXT_DATA__').text());
|
||
const nextBuildId = nextData.buildId;
|
||
const { data: response } = await got(`${baseUrl}/_next/data/${nextBuildId}/${topic}.json${topicIdParam}`);
|
||
const title = `${response.pageProps.label_name} - ドラえもんチャンネル`;
|
||
const contents = response.pageProps.contents;
|
||
const list = contents.map((item) => ({
|
||
title: item.title,
|
||
link: item.page_url.startsWith('http') ? item.page_url : `${baseUrl}${item.page_url}`,
|
||
description: item.page_url.startsWith('/contents/') ? '' : `<p>${item.title}</p><img src="${item.image_url}" alt="">`,
|
||
pubDate: timezone(parseDate(item.publish_at), 9),
|
||
category: item.tags.map((tag) => tag.name),
|
||
guid: item.id,
|
||
}));
|
||
return {
|
||
title,
|
||
link,
|
||
language: 'ja',
|
||
image: 'https://dora-world.com/assets/images/DORAch_web-touch-icon.png',
|
||
item: (await Promise.all(
|
||
list.map(
|
||
async (item) =>
|
||
await cache.tryGet(item.link, async () => {
|
||
if (item.description === '') {
|
||
item.description = await getContent(nextBuildId, item.guid);
|
||
}
|
||
return item;
|
||
})
|
||
)
|
||
)) as DataItem[],
|
||
};
|
||
}
|
||
|
||
async function getContent(nextBuildId: string, contentId: string) {
|
||
const { data: response } = await got(`${baseUrl}/_next/data/${nextBuildId}/contents/${contentId}.json`);
|
||
const $ = load(response.pageProps.content.content);
|
||
const content = $('.main_unit');
|
||
content.find('.tag').remove();
|
||
content.find('div[style="display:none"]').remove();
|
||
const rubyRegex = /<ruby>(.*?)<rt>(.*?)<\/rt><\/ruby>/g;
|
||
const description =
|
||
content
|
||
.html()
|
||
?.replaceAll(rubyRegex, '$1($2)')
|
||
?.replaceAll(/[^\t\n\r\u{0020}-\u{D7FF}\u{E000}-\u{FDCF}\u{FDE0}-\u{FFFD}]/gu, '') ?? '';
|
||
return description;
|
||
}
|