Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/extractors/x-article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
12 changes: 12 additions & 0 deletions tests/expected/general--x.com-status-localized-author.md
Original file line number Diff line number Diff line change
@@ -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.
24 changes: 24 additions & 0 deletions tests/fixtures/general--x.com-status-localized-author.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- {"url":"https://x.com/sample_user/status/1234567890123456789"} -->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta property="og:title" content="X 上的 Sample Name:“Localized author fallback example” / X">
<title>X 上的 Sample Name:“Localized author fallback example” / X</title>
</head>
<body>
<div data-testid="twitter-article-title">Localized author fallback example</div>
<div data-testid="twitterArticleRichTextView">
<div class="longform-unstyled">
<div class="public-DraftStyleDefault-block" data-offset-key="abc123">
This fixture simulates an X article rendered on a status URL without an inline author block.
</div>
</div>
<div class="longform-unstyled">
<div class="public-DraftStyleDefault-block" data-offset-key="def456">
The author should fall back to the handle embedded in the page URL.
</div>
</div>
</div>
</body>
</html>