Skip to content

Commit 8d8a435

Browse files
lucky13820Ryan YaoRyan YaoRyan Yao
authored
fix(route/theinitium): rewrite for Ghost CMS after site migration (#21071)
* refactor(theinitium): rewrite routes for Ghost CMS, add cookie support - Rewrite all routes to use Ghost Content API (old API deprecated) - Add INITIUM_MEMBER_COOKIE env var for paid article full-text - Add features block with requireConfig to all route files - Add url field and radar rules per RSSHub standards - Strip -zh-hans suffix from author/category display names - Update namespace with English name and zh translations - Mark follow route as deprecated (Ghost doesn't support it) - Fix hostname binding to 0.0.0.0 for LAN access * fix(theinitium): use routeExpire with refresh=false to prevent stale cache Cache was never expiring because refresh=true (default) extends TTL on every hit. Now uses 5-min routeExpire and won't extend on access. * refactor(theinitium): address review feedback - Remove unused INITIUM_USERNAME/PASSWORD/BEARER_TOKEN env keys - Remove hardcoded User-Agent (use RSSHub's internal UA) - Remove fragile html.length > 500 check - Remove refresh: false from cache.tryGet - Hoist stripLangSuffix to module scope (dedupe with cleanName) * fix(theinitium): detect paywall CTA instead of length check If cookie is invalid/expired, scrape returns paywall HTML. Check for .gh-post-upgrade-cta to detect this and fall back to cleaner Ghost API preview. * revert(index): restore '::' hostname per #16513 * feat(theinitium): clean Ghost Koenig card HTML for RSS output * fix(theinitium): use redirected Ghost API URL, remove unused config types * fix(theinitium): remove unrelated neureality config changes --------- Co-authored-by: Ryan Yao <ryanyao@Macmini.lan> Co-authored-by: Ryan Yao <ryanyao@Ryans-Mac-mini.lan> Co-authored-by: Ryan Yao <ryanyao@Ryans-Mac-mini.local>
1 parent 5277218 commit 8d8a435

File tree

7 files changed

+372
-201
lines changed

7 files changed

+372
-201
lines changed

lib/config.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ type ConfigEnvKeys =
120120
| 'HEFENG_API_HOST'
121121
| 'HUITUN_COOKIE'
122122
| 'INFZM_COOKIE'
123-
| 'INITIUM_USERNAME'
124-
| 'INITIUM_PASSWORD'
125-
| 'INITIUM_BEARER_TOKEN'
123+
| 'INITIUM_MEMBER_COOKIE'
126124
| 'IG_USERNAME'
127125
| 'IG_PASSWORD'
128126
| 'IG_PROXY'
@@ -444,9 +442,7 @@ export type Config = {
444442
cookie?: string;
445443
};
446444
initium: {
447-
username?: string;
448-
password?: string;
449-
bearertoken?: string;
445+
memberCookie?: string;
450446
};
451447
instagram: {
452448
username?: string;
@@ -934,9 +930,7 @@ const calculateValue = () => {
934930
cookie: envs.INFZM_COOKIE,
935931
},
936932
initium: {
937-
username: envs.INITIUM_USERNAME,
938-
password: envs.INITIUM_PASSWORD,
939-
bearertoken: envs.INITIUM_BEARER_TOKEN,
933+
memberCookie: envs.INITIUM_MEMBER_COOKIE,
940934
},
941935
instagram: {
942936
username: envs.IG_USERNAME,

lib/routes/theinitium/author.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,25 @@ const handler = (ctx) => processFeed('author', ctx);
77
export const route: Route = {
88
path: '/author/:type/:language?',
99
name: '作者',
10+
url: 'theinitium.com',
1011
maintainers: ['AgFlore'],
1112
parameters: {
12-
type: '作者 ID,可从作者主页 URL 中获取,如 `https://theinitium.com/author/ninghuilulu`',
13-
language: '语言,简体`zh-hans`,繁体`zh-hant`,缺省为简体',
13+
type: '作者 slug,可从作者主页 URL 中获取,如 `https://theinitium.com/author/initium-newsroom/`',
14+
language: '语言,简体`zh-hans`,繁体`zh-hant`,缺省为不限',
15+
},
16+
features: {
17+
requireConfig: [
18+
{
19+
name: 'INITIUM_MEMBER_COOKIE',
20+
optional: true,
21+
description: '端传媒会员登录后的 Cookie,用于获取付费文章全文。',
22+
},
23+
],
24+
requirePuppeteer: false,
25+
antiCrawler: false,
26+
supportBT: false,
27+
supportPodcast: false,
28+
supportScihub: false,
1429
},
1530
radar: [
1631
{
@@ -19,6 +34,6 @@ export const route: Route = {
1934
},
2035
],
2136
handler,
22-
example: '/theinitium/author/ninghuilulu/zh-hans',
37+
example: '/theinitium/author/initium-newsroom',
2338
categories: ['new-media'],
2439
};

lib/routes/theinitium/channel.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,47 @@ const handler = (ctx) => processFeed('channel', ctx);
66

77
export const route: Route = {
88
path: '/channel/:type?/:language?',
9-
name: '专题・栏目',
9+
name: '栏目',
10+
url: 'theinitium.com',
1011
maintainers: ['prnake', 'mintyfrankie'],
1112
parameters: {
12-
type: '栏目,缺省为最新',
13-
language: '语言,简体`zh-hans`,繁体`zh-hant`,缺省为简体',
13+
type: '栏目,缺省为最新(latest)',
14+
language: '语言,简体`zh-hans`,繁体`zh-hant`,缺省为不限',
15+
},
16+
features: {
17+
requireConfig: [
18+
{
19+
name: 'INITIUM_MEMBER_COOKIE',
20+
optional: true,
21+
description: '端传媒会员登录后的 Cookie,用于获取付费文章全文。获取方式:登录 theinitium.com 后,从浏览器开发者工具中复制 Cookie。',
22+
},
23+
],
24+
requirePuppeteer: false,
25+
antiCrawler: false,
26+
supportBT: false,
27+
supportPodcast: false,
28+
supportScihub: false,
1429
},
1530
radar: [
1631
{
17-
source: ['theinitium.com/channel/:type'],
32+
source: ['theinitium.com/latest/'],
33+
target: '/channel/latest',
34+
},
35+
{
36+
source: ['theinitium.com/tag/:type'],
1837
target: '/channel/:type',
1938
},
2039
],
2140
handler,
22-
example: '/theinitium/channel/latest/zh-hans',
41+
example: '/theinitium/channel/latest',
2342
categories: ['new-media'],
24-
description: `Type 栏目:
43+
description: `Type 栏目(对应 Ghost 标签):
44+
45+
| 最新 | 速递 | 评论 | 国际 | 大陆 | 香港 | 台湾 | 科技 | 专题 | 日报 | 周报 |
46+
| ------ | -------- | ------- | ------------- | -------- | -------- | ------ | ---------- | ------ | ----------- | ------ |
47+
| latest | whatsnew | opinion | international | mainland | hongkong | taiwan | technology | feature | daily-brief | weekly |
2548
26-
| 最新 | 深度 | What’s New | 广场 | 科技 | 风物 | 特约 | ... |
27-
| ------ | ------- | ---------- | ----------------- | ---------- | ------- | -------- | --- |
28-
| latest | feature | news-brief | notes-and-letters | technology | culture | pick_up | ... |`,
49+
:::tip
50+
设置环境变量 \`INITIUM_MEMBER_COOKIE\` 可获取付费文章全文。
51+
:::`,
2952
};

lib/routes/theinitium/follow.ts

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,19 @@
11
import type { Route } from '@/types';
22

3-
import { processFeed } from './utils';
4-
5-
const handler = (ctx) => processFeed('follow', ctx);
6-
73
export const route: Route = {
84
path: '/follow/articles/:language?',
9-
name: '个人订阅追踪动态',
5+
name: '个人订阅追踪动态(已停用)',
106
maintainers: ['AgFlore'],
117
parameters: {
12-
language: '语言,简体`zh-hans`,繁体`zh-hant`,缺省为简体',
8+
language: '语言',
139
},
14-
radar: [
15-
{
16-
title: '作者',
17-
source: ['theinitium.com/author/:type'],
18-
target: '/author/:type',
19-
},
20-
],
21-
handler,
22-
example: '/theinitium/author/ninghuilulu/zh-hans',
23-
categories: ['new-media'],
24-
description: '需填入 Web 版认证 token, 也可选择直接在环境设置中填写明文的用户名和密码',
25-
features: {
26-
requireConfig: [
27-
{
28-
name: 'INITIUM_BEARER_TOKEN',
29-
optional: true,
30-
description: `端传媒 Web 版认证 token。获取方式:登陆后打开端传媒站内任意页面,打开浏览器开发者工具中 “网络”(Network) 选项卡,筛选 URL 找到任一个地址为 \`api.initium.com\` 开头的请求,点击检查其 “消息头”,在 “请求头” 中找到Authorization字段,将其值复制填入配置即可。你的配置应该形如 \`INITIUM_BEARER_TOKEN: 'Bearer eyJxxxx......xx_U8'\`。使用 token 部署的好处是避免占据登陆设备数的额度,但这个 token 一般有效期为两周,因此只可作临时测试使用。`,
31-
},
32-
{
33-
name: 'INITIUM_USERNAME',
34-
optional: true,
35-
description: `端传媒用户名 (邮箱)`,
36-
},
37-
{
38-
name: 'INITIUM_PASSWORD',
39-
optional: true,
40-
description: `端传媒密码`,
41-
},
42-
],
10+
radar: [],
11+
handler: () => {
12+
throw new Error('此路由已停用。端传媒迁移到 Ghost CMS 后不再支持个人追踪功能。请改用 /theinitium/channel/latest 或 /theinitium/tags/:tag 订阅。');
4313
},
14+
example: '/theinitium/follow/articles',
15+
categories: ['new-media'],
16+
description: `:::warning
17+
此路由已停用。端传媒已迁移到 Ghost CMS,不再支持通过 API 获取个人追踪内容。请改用标签或栏目订阅。
18+
:::`,
4419
};

lib/routes/theinitium/namespace.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import type { Namespace } from '@/types';
22

33
export const namespace: Namespace = {
4-
name: '端传媒',
4+
name: 'The Initium',
55
url: 'theinitium.com',
6-
description: `通过提取文章全文,以提供比官方源更佳的阅读体验。
6+
description: `:::tip
7+
Set the environment variable \`INITIUM_MEMBER_COOKIE\` to get the full text of paid articles. After logging in to theinitium.com, copy the Cookie from the browser developer tools.
78
8-
::: warning
9-
付费内容全文可能需要登陆获取,详情见部署页面的配置模块。
9+
Old environment variables \`INITIUM_USERNAME\`, \`INITIUM_PASSWORD\`, and \`INITIUM_BEARER_TOKEN\` are no longer used since the site migrated to Ghost CMS.
1010
:::`,
11-
lang: 'zh-HK',
11+
12+
zh: {
13+
name: '端傳媒',
14+
description: `:::tip
15+
设置环境变量 \`INITIUM_MEMBER_COOKIE\` 可获取付费文章全文。登录 theinitium.com 后,从浏览器开发者工具中复制 Cookie。
16+
17+
旧的环境变量 \`INITIUM_USERNAME\`、\`INITIUM_PASSWORD\` 和 \`INITIUM_BEARER_TOKEN\` 已不再使用(网站已迁移至 Ghost CMS)。
18+
:::`,
19+
},
1220
};

lib/routes/theinitium/tags.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,33 @@ const handler = (ctx) => processFeed('tags', ctx);
77
export const route: Route = {
88
path: '/tags/:type/:language?',
99
name: '话题・标签',
10+
url: 'theinitium.com',
1011
maintainers: ['AgFlore'],
1112
parameters: {
12-
type: '话题 ID,可从话题页 URL 中获取,如 `https://theinitium.com/tags/2019_10/`',
13-
language: '语言,简体`zh-hans`,繁体`zh-hant`,缺省为简体',
13+
type: '标签 slug,可从标签页 URL 中获取,如 `https://theinitium.com/tag/south-korea/` 则为 `south-korea`',
14+
language: '语言,简体`zh-hans`,繁体`zh-hant`,缺省为不限',
15+
},
16+
features: {
17+
requireConfig: [
18+
{
19+
name: 'INITIUM_MEMBER_COOKIE',
20+
optional: true,
21+
description: '端传媒会员登录后的 Cookie,用于获取付费文章全文。',
22+
},
23+
],
24+
requirePuppeteer: false,
25+
antiCrawler: false,
26+
supportBT: false,
27+
supportPodcast: false,
28+
supportScihub: false,
1429
},
1530
radar: [
1631
{
17-
source: ['theinitium.com/tags/:type'],
32+
source: ['theinitium.com/tag/:type'],
1833
target: '/tags/:type',
1934
},
2035
],
2136
handler,
22-
example: '/theinitium/tags/2019_10/zh-hans',
37+
example: '/theinitium/tags/south-korea',
2338
categories: ['new-media'],
2439
};

0 commit comments

Comments
 (0)