From 249cedc0d4ceef9c42b1e797ee0e3f01494db875 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 24 May 2024 12:48:15 +0800 Subject: [PATCH] fix(route): nikkei route paths (#15684) --- lib/routes/nikkei/asia/index.ts | 11 +-------- lib/routes/nikkei/cn/index.ts | 42 ++++++++++++++++++++++++++++++--- lib/routes/nikkei/index.ts | 9 +++---- lib/routes/nikkei/namespace.ts | 2 +- lib/routes/nikkei/news.ts | 4 ++-- 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/lib/routes/nikkei/asia/index.ts b/lib/routes/nikkei/asia/index.ts index 75d29f5fc..0f36c8b82 100644 --- a/lib/routes/nikkei/asia/index.ts +++ b/lib/routes/nikkei/asia/index.ts @@ -8,15 +8,6 @@ export const route: Route = { path: '/asia', categories: ['traditional-media'], example: '/nikkei/asia', - parameters: {}, - features: { - requireConfig: false, - requirePuppeteer: false, - antiCrawler: false, - supportBT: false, - supportPodcast: false, - supportScihub: false, - }, radar: [ { source: ['asia.nikkei.com/'], @@ -25,7 +16,7 @@ export const route: Route = { name: 'Nikkei Asia Latest News', maintainers: ['rainrdx'], handler, - url: 'asia.nikkei.com/', + url: 'asia.nikkei.com', }; async function handler() { diff --git a/lib/routes/nikkei/cn/index.ts b/lib/routes/nikkei/cn/index.ts index ef0d7d1c5..31309bb0c 100644 --- a/lib/routes/nikkei/cn/index.ts +++ b/lib/routes/nikkei/cn/index.ts @@ -9,9 +9,45 @@ import parser from '@/utils/rss-parser'; export const route: Route = { path: '/cn/*', - name: 'Unknown', - maintainers: [], + name: '中文版新闻', + example: '/nikkei/cn', + maintainers: ['nczitzk'], handler, + description: `::: tip + 如 [中国 经济 日经中文网](https://cn.nikkei.com/china/ceconomy.html) 的 URL 为 \`https://cn.nikkei.com/china/ceconomy.html\` 对应路由为 [\`/nikkei/cn/cn/china/ceconomy\`](https://rsshub.app/nikkei/cn/cn/china/ceconomy) + + 如 [中國 經濟 日經中文網](https://zh.cn.nikkei.com/china/ceconomy.html) 的 URL 为 \`https://zh.cn.nikkei.com/china/ceconomy.html\` 对应路由为 [\`/nikkei/cn/zh/china/ceconomy\`](https://rsshub.app/nikkei/cn/zh/china/ceconomy) + + 特别地,当 \`path\` 填入 \`rss\` 后(如路由为 [\`/nikkei/cn/cn/rss\`](https://rsshub.app/nikkei/cn/cn/rss)),此时返回的是 [官方 RSS 的内容](https://cn.nikkei.com/rss.html) +:::`, + radar: [ + { + title: '中文版新闻', + source: ['cn.nikkei.com/:category/:type', 'cn.nikkei.com/:category', 'cn.nikkei.com/'], + target: (params) => { + if (params.category && params.type) { + return `/nikkei/cn/cn/${params.category}/${params.type.replace('.html', '')}`; + } else if (params.category && !params.type) { + return `/nikkei/cn/cn/${params.category.replace('.html', '')}`; + } else { + return `/nikkei/cn/cn`; + } + }, + }, + { + title: '中文版新聞', + source: ['zh.cn.nikkei.com/:category/:type', 'zh.cn.nikkei.com/:category', 'zh.cn.nikkei.com/'], + target: (params) => { + if (params.category && params.type) { + return `/nikkei/cn/zh/${params.category}/${params.type.replace('.html', '')}`; + } else if (params.category && !params.type) { + return `/nikkei/cn/zh/${params.category.replace('.html', '')}`; + } else { + return `/nikkei/cn/zh`; + } + }, + }, + ], }; async function handler(ctx) { @@ -40,7 +76,7 @@ async function handler(ctx) { officialFeed = await parser.parseURL(currentUrl); items = officialFeed.items.slice(0, limit).map((item) => ({ title: item.title, - link: new URL(item.attr('href'), rootUrl).href, + link: new URL(item.link, rootUrl).href, })); } else { const response = await got({ diff --git a/lib/routes/nikkei/index.ts b/lib/routes/nikkei/index.ts index 3767f2a55..ae0cb2f57 100644 --- a/lib/routes/nikkei/index.ts +++ b/lib/routes/nikkei/index.ts @@ -3,11 +3,12 @@ import got from '@/utils/got'; import { load } from 'cheerio'; export const route: Route = { - path: ['/', '/index'], - name: 'Unknown', - maintainers: [], + path: '/index', + name: 'Home', + example: '/nikkei/index', + maintainers: ['zjysdhr'], handler, - url: 'www.nikkei.com/', + url: 'www.nikkei.com', }; async function handler() { diff --git a/lib/routes/nikkei/namespace.ts b/lib/routes/nikkei/namespace.ts index ea3cef383..a67b3cba9 100644 --- a/lib/routes/nikkei/namespace.ts +++ b/lib/routes/nikkei/namespace.ts @@ -2,5 +2,5 @@ import type { Namespace } from '@/types'; export const namespace: Namespace = { name: 'The Nikkei 日本経済新聞', - url: 'asia.nikkei.com', + url: 'nikkei.com', }; diff --git a/lib/routes/nikkei/news.ts b/lib/routes/nikkei/news.ts index 757dd8d99..21bafbff3 100644 --- a/lib/routes/nikkei/news.ts +++ b/lib/routes/nikkei/news.ts @@ -10,9 +10,9 @@ import { art } from '@/utils/render'; import path from 'node:path'; export const route: Route = { - path: '/:category/:article_type?', + path: '/news/:category/:article_type?', categories: ['traditional-media'], - example: '/nikkei/news', + example: '/nikkei/news/news', parameters: { category: 'Category, see table below', article_type: 'Only includes free articles, set `free` to enable, disabled by default' }, radar: [ {