diff --git a/lib/routes/theinitium/app.ts b/lib/routes/theinitium/app.ts index aa5ac4c55..5aa278973 100644 --- a/lib/routes/theinitium/app.ts +++ b/lib/routes/theinitium/app.ts @@ -1,16 +1,51 @@ -import type { CheerioAPI } from 'cheerio'; -import { load } from 'cheerio'; -import type { Element } from 'domhandler'; - -import { config } from '@/config'; import type { Route } from '@/types'; -import cache from '@/utils/cache'; -import ofetch from '@/utils/ofetch'; -import { renderDescription } from './templates/description'; +import { applyLanguageToTagSlug, CHANNEL_TAG_MAP, ghostFetch, postsToItems } from './utils'; -const appUrl = 'https://app.theinitium.com/'; -const userAgent = 'PugpigBolt v4.1.8 (iPhone, iOS 18.2.1) on phone (model iPhone15,2)'; +// Reason: Old app categories map to Ghost channel tag + language. +// The _sc suffix = Simplified Chinese (zh-hans), _tc = Traditional Chinese (zh-hant). +const APP_CATEGORY_MAP: Record = { + latest_sc: { channelType: 'latest', language: 'zh-hans' }, + latest_tc: { channelType: 'latest', language: 'zh-hant' }, + daily_brief_sc: { channelType: 'daily-brief', language: 'zh-hans' }, + daily_brief_tc: { channelType: 'daily-brief', language: 'zh-hant' }, + whats_new_sc: { channelType: 'whatsnew', language: 'zh-hans' }, + whats_new_tc: { channelType: 'whatsnew', language: 'zh-hant' }, + report_sc: { channelType: 'feature', language: 'zh-hans' }, + report_tc: { channelType: 'feature', language: 'zh-hant' }, + opinion_sc: { channelType: 'opinion', language: 'zh-hans' }, + opinion_tc: { channelType: 'opinion', language: 'zh-hant' }, + international_sc: { channelType: 'international', language: 'zh-hans' }, + international_tc: { channelType: 'international', language: 'zh-hant' }, + mainland_sc: { channelType: 'mainland', language: 'zh-hans' }, + mainland_tc: { channelType: 'mainland', language: 'zh-hant' }, + hongkong_sc: { channelType: 'hongkong', language: 'zh-hans' }, + hongkong_tc: { channelType: 'hongkong', language: 'zh-hant' }, + taiwan_sc: { channelType: 'taiwan', language: 'zh-hans' }, + taiwan_tc: { channelType: 'taiwan', language: 'zh-hant' }, +}; + +// Reason: Display labels for the old app categories, kept for RSS feed titles +const APP_CATEGORY_LABELS: Record = { + latest_sc: '最新', + latest_tc: '最新', + daily_brief_sc: '日报', + daily_brief_tc: '日報', + whats_new_sc: '速递', + whats_new_tc: '速遞', + report_sc: '专题', + report_tc: '專題', + opinion_sc: '评论', + opinion_tc: '評論', + international_sc: '国际', + international_tc: '國際', + mainland_sc: '大陆', + mainland_tc: '大陸', + hongkong_sc: '香港', + hongkong_tc: '香港', + taiwan_sc: '台湾', + taiwan_tc: '台灣', +}; export const route: Route = { path: '/app/:category?', @@ -20,6 +55,13 @@ export const route: Route = { category: 'Category, see below, latest_sc by default', }, features: { + requireConfig: [ + { + name: 'INITIUM_MEMBER_COOKIE', + optional: true, + description: '端传媒会员登录后的 Cookie,用于获取付费文章全文。', + }, + ], requirePuppeteer: false, antiCrawler: false, supportBT: false, @@ -30,18 +72,12 @@ export const route: Route = { maintainers: ['quiniapiezoelectricity'], radar: [ { - source: ['app.theinitium.com/t/latest/:category'], - target: '/app/:category', + source: ['theinitium.com/latest/'], + target: '/app/latest_sc', }, ], handler, - description: `抓取[The Initium App](https://app.theinitium.com/)的文章列表 - -::: warning -此路由暂不支持登陆认证 -::: - -Category 栏目: + description: `Category 栏目: | ----- | 简体中文 | 繁體中文 | | ----- | ----------------- | ---------------- | @@ -54,139 +90,50 @@ Category 栏目: | 大陆 | mainland_sc | mainland_tc | | 香港 | hongkong_sc | hongkong_tc | | 台湾 | taiwan_sc | taiwan_tc | -| 播客 | article_audio_sc | article_audio_tc |`, + +:::tip +原 App 路由已迁移至 Ghost CMS API。播客(article_audio)分类已停用,请改用 \`/theinitium/channel\` 路由。 +:::`, }; -const resolveRelativeLink = ($: CheerioAPI, elem: Element, attr: string, appUrl?: string) => { - // code from @/middleware/paratmeter.ts - const $elem = $(elem); - - if (appUrl) { - try { - const oldAttr = $elem.attr(attr); - if (oldAttr) { - // e.g. should leave