From 3da86a21dc40baf8ca12d8a9600c3574cdb289ef Mon Sep 17 00:00:00 2001 From: Leven Ye <93325995+ylw5@users.noreply.github.com> Date: Fri, 13 Mar 2026 01:16:53 +0800 Subject: [PATCH] Fix X author fallback on status URLs --- src/extractors/x-article.ts | 5 ++-- .../general--x.com-status-localized-author.md | 12 ++++++++++ ...eneral--x.com-status-localized-author.html | 24 +++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/expected/general--x.com-status-localized-author.md create mode 100644 tests/fixtures/general--x.com-status-localized-author.html diff --git a/src/extractors/x-article.ts b/src/extractors/x-article.ts index d65a25a32..e3948abf8 100644 --- a/src/extractors/x-article.ts +++ b/src/extractors/x-article.ts @@ -69,8 +69,9 @@ export class XArticleExtractor extends BaseExtractor { } private getAuthorFromUrl(): string { - // match username before /article/, excluding system paths like /i/ - const match = this.url.match(/\/([a-zA-Z][a-zA-Z0-9_]{0,14})\/article\/\d+/); + // X articles can render on both /article/ and /status/ URLs. + // Prefer the handle from the URL when available, excluding system paths like /i/. + const match = this.url.match(/\/([a-zA-Z][a-zA-Z0-9_]{0,14})\/(?:status|article)\/\d+/); return match ? `@${match[1]}` : this.getAuthorFromOgTitle(); } diff --git a/tests/expected/general--x.com-status-localized-author.md b/tests/expected/general--x.com-status-localized-author.md new file mode 100644 index 000000000..74303f1ba --- /dev/null +++ b/tests/expected/general--x.com-status-localized-author.md @@ -0,0 +1,12 @@ +```json +{ + "title": "Localized author fallback example", + "author": "@sample_user", + "site": "X (Twitter)", + "published": "" +} +``` + +This fixture simulates an X article rendered on a status URL without an inline author block. + +The author should fall back to the handle embedded in the page URL. diff --git a/tests/fixtures/general--x.com-status-localized-author.html b/tests/fixtures/general--x.com-status-localized-author.html new file mode 100644 index 000000000..160c262c1 --- /dev/null +++ b/tests/fixtures/general--x.com-status-localized-author.html @@ -0,0 +1,24 @@ + + + + + + + X 上的 Sample Name:“Localized author fallback example” / X + + +
Localized author fallback example
+
+
+
+ This fixture simulates an X article rendered on a status URL without an inline author block. +
+
+
+
+ The author should fall back to the handle embedded in the page URL. +
+
+
+ +