Skip to content

Commit 2f96c63

Browse files
committed
chore(x): consistent author/description
1 parent 73e181e commit 2f96c63

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

packages/metascraper-x/src/index.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ module.exports = ({ resolveUrl = url => url } = {}) => {
3030
author: [
3131
toAuthor($ => {
3232
const author = $('meta[property="og:title"]').attr('content')
33-
return author?.includes(' / X') ? author.split(' / X')[0] : author
33+
if (!author) return
34+
return author
35+
.split(' / X')[0]
36+
.split(' on X:')[0]
37+
.split(' on X')[0]
38+
.split(' (@')[0]
39+
.trim()
3440
})
3541
],
3642
title: [
@@ -49,6 +55,22 @@ module.exports = ({ resolveUrl = url => url } = {}) => {
4955
$jsonld('mainEntity.description')($) ||
5056
$('meta[property="og:description"]').attr('content')
5157

58+
if (!description) {
59+
const ogTitle = $('meta[property="og:title"]').attr('content')
60+
if (ogTitle?.includes(' on X: "')) {
61+
description = ogTitle.split(' on X: "')[1].split('" / X')[0]
62+
const urls = getUrls(description)
63+
if (urls.length > 1) {
64+
const lastUrl = urls[urls.length - 1]
65+
if (description.endsWith(lastUrl)) {
66+
description = description.replace(lastUrl, '').trim()
67+
}
68+
}
69+
}
70+
}
71+
72+
if (!description) return
73+
5274
const urls = getUrls(description)
5375
const resolvedUrls = await Promise.all(urls.map(resolveUrl))
5476

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<!DOCTYPE html><html dir="ltr" lang="en"><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0,viewport-fit=cover" /><link rel="preconnect" href="//abs.twimg.com" /><link rel="dns-prefetch" href="//abs.twimg.com" /><link rel="preconnect" href="//api.twitter.com" /><link rel="dns-prefetch" href="//api.twitter.com" /><link rel="preconnect" href="//api.x.com" /><link rel="dns-prefetch" href="//api.x.com" /><link rel="preconnect" href="//pbs.twimg.com" /><link rel="dns-prefetch" href="//pbs.twimg.com" /><link rel="preconnect" href="//t.co" /><link rel="dns-prefetch" href="//t.co" /><link rel="preconnect" href="//video.twimg.com" /><link rel="dns-prefetch" href="//video.twimg.com" /><meta http-equiv="onion-location" content="https://twitter3e4tixl4xyajtrzo62zg5vztmjuricljdp2c5kshju4avyoid.onion/" /><meta property="fb:app_id" content="2231777543" /><meta content="X (formerly Twitter)" property="og:site_name" /><meta name="google-site-verification" content="600dQ0pZYsH2xOFt4hYmf5f5NpjCbWE_qk5Y04dErYM" /><meta name="facebook-domain-verification" content="x6sdcc8b5ju3bh8nbm59eswogvg6t1" /><meta name="mobile-web-app-capable" content="yes" /><meta name="apple-mobile-web-app-title" content="Twitter" /><meta name="apple-mobile-web-app-status-bar-style" content="white" /><link rel="search" type="application/opensearchdescription+xml" href="/os-x.xml" title="X">
2-
<link rel="search" type="application/opensearchdescription+xml" href="/os-grok.xml" title="Grok"><link rel="manifest" href="/manifest.json" crossOrigin="use-credentials" /><link rel="search" type="application/opensearchdescription+xml" href="/os-x.xml" title="X"><link rel="search" type="application/opensearchdescription+xml" href="/os-grok.xml" title="Grok"><link rel="shortcut icon" href="//abs.twimg.com/favicons/twitter.3.ico"><meta name="theme-color" media="(prefers-color-scheme: light)" content="#FFFFFF" /><meta name="theme-color" media="(prefers-color-scheme: dark)" content="#000000" /><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebSite","url":"https://twitter.com/","potentialAction":{"@type":"SearchAction","query-input":"required name=search_term_string","target":{"@type":"EntryPoint","urlTemplate":"https://twitter.com/search?q={search_term_string}&ref_src=twcamp%5Eseo_searchbox%7Ctwsrc%5Eseo"}}}</script><meta http-equiv="origin-trial" content="AlpCmb40F5ZjDi9ZYe+wnr/V8MF+XmY41K4qUhoq+2mbepJTNd3q4CRqlACfnythEPZqcjryfAS1+ExS0FFRcA8AAABmeyJvcmlnaW4iOiJodHRwczovL3R3aXR0ZXIuY29tOjQ0MyIsImZlYXR1cmUiOiJMYXVuY2ggSGFuZGxlciIsImV4cGlyeSI6MTY1NTI1MTE5OSwiaXNTdWJkb21haW4iOnRydWV9" /><style>html,body{height: 100%;}::cue{white-space:normal}</style><meta content="article" property="og:type" /><meta content="https://twitter.com/UaSmart/status/934106870834454529" property="og:url" /><meta content="SmartUA (@UaSmart) on X" property="og:title" /><meta content="Y terminamos el dia con Cultura de empresa con @patoroco, @flopezluis, Katia, Angélica en @codemotion_es #codemotion2017" property="og:description" /><meta content="https://pbs.twimg.com/media/DPadOKpXcAIL-NW.jpg:large" property="og:image" /><meta content="Y terminamos el dia con Cultura de empresa con @patoroco, @flopezluis, Katia, Angélica en @codemotion_es #codemotion2017" name="description" /><meta content="SmartUA (@UaSmart) on X" name="title" /><meta content="twitter://status?id=934106870834454529" property="al:ios:url" /><meta content="333903271" property="al:ios:app_store_id" /><meta content="X" property="al:ios:app_name" /><meta content="twitter://status?id=934106870834454529" property="al:android:url" /><meta content="com.twitter.android" property="al:android:package" /><meta content="X" property="al:android:app_name" /></head><body style="background-color: #FFFFFF;"><div id="react-root" style="height:100%;display:flex;"></div>
2+
<link rel="search" type="application/opensearchdescription+xml" href="/os-grok.xml" title="Grok"><link rel="manifest" href="/manifest.json" crossOrigin="use-credentials" /><link rel="search" type="application/opensearchdescription+xml" href="/os-x.xml" title="X"><link rel="search" type="application/opensearchdescription+xml" href="/os-grok.xml" title="Grok"><link rel="shortcut icon" href="//abs.twimg.com/favicons/twitter.3.ico"><meta name="theme-color" media="(prefers-color-scheme: light)" content="#FFFFFF" /><meta name="theme-color" media="(prefers-color-scheme: dark)" content="#000000" /><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebSite","url":"https://twitter.com/","potentialAction":{"@type":"SearchAction","query-input":"required name=search_term_string","target":{"@type":"EntryPoint","urlTemplate":"https://twitter.com/search?q={search_term_string}&ref_src=twcamp%5Eseo_searchbox%7Ctwsrc%5Eseo"}}}</script><meta http-equiv="origin-trial" content="AlpCmb40F5ZjDi9ZYe+wnr/V8MF+XmY41K4qUhoq+2mbepJTNd3q4CRqlACfnythEPZqcjryfAS1+ExS0FFRcA8AAABmeyJvcmlnaW4iOiJodHRwczovL3R3aXR0ZXIuY29tOjQ0MyIsImZlYXR1cmUiOiJMYXVuY2ggSGFuZGxlciIsImV4cGlyeSI6MTY1NTI1MTE5OSwiaXNTdWJkb21haW4iOnRydWV9" /><style>html,body{height: 100%;}::cue{white-space:normal}</style><meta content="article" property="og:type" /><meta content="https://twitter.com/realDonaldTrump/status/1222907250383245320" property="og:url" /><meta content="Donald J. Trump (@realDonaldTrump) on X" property="og:title" /><meta content="“Schiff blasted for not focusing on California homeless.” @foxandfriends His District is in terrible shape. He is a corrupt pol who only dreams of the Impeachment Hoax. In my opinion he is mentally deranged!" property="og:description" /><meta content="https://pbs.twimg.com/profile_images/874276197357596672/kUuht00m_200x200.jpg" property="og:image" /><meta content="“Schiff blasted for not focusing on California homeless.” @foxandfriends His District is in terrible shape. He is a corrupt pol who only dreams of the Impeachment Hoax. In my opinion he is mentally deranged!" name="description" /><meta content="Donald J. Trump (@realDonaldTrump) on X" name="title" /><meta content="twitter://status?id=1222907250383245320" property="al:ios:url" /><meta content="333903271" property="al:ios:app_store_id" /><meta content="X" property="al:ios:app_name" /><meta content="twitter://status?id=1222907250383245320" property="al:android:url" /><meta content="com.twitter.android" property="al:android:package" /><meta content="X" property="al:android:app_name" /></head><body style="background-color: #FFFFFF;"><div id="react-root" style="height:100%;display:flex;"></div>

packages/metascraper-x/test/snapshots/index.js.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Generated by [AVA](https://avajs.dev).
99
> Snapshot 1
1010
1111
{
12-
author: 'Kiko Beats (Kikobeats)',
12+
author: 'Kiko Beats',
1313
date: '2025-11-09T13:11:55.000Z',
1414
description: 'Building web infra & open source Running https://t.co/4PQvCsVNsA · https://t.co/IG8Qq0IDKi Formerly @vercel ▲',
1515
image: 'https://pbs.twimg.com/profile_images/2000931726244106244/Ty7-KT2j_400x400.jpg',
@@ -25,7 +25,7 @@ Generated by [AVA](https://avajs.dev).
2525
> Snapshot 1
2626
2727
{
28-
author: '#!/kiko/beats (Kikobeats) on X',
28+
author: '#!/kiko/beats',
2929
date: null,
3030
description: 'engineering ▲ @vercel; founder of https://t.co/4PQvCsVNsA https://t.co/fpiHwbEPBv https://t.co/IG8Qq0IDKi https://t.co/gblDRx1P9D https://t.co/SmoZi3hAhb https://t.co/Y0Uk1XU3Eu https://t.co/PAq3eTEhmI',
3131
image: 'https://pbs.twimg.com/profile_images/1846292082501054464/oKUC44PF_400x400.jpg',
@@ -41,7 +41,7 @@ Generated by [AVA](https://avajs.dev).
4141
> Snapshot 1
4242
4343
{
44-
author: 'Kiko Beats (Kikobeats)',
44+
author: 'Kiko Beats',
4545
date: '2025-11-09T13:11:55.000Z',
4646
description: 'Building web infra & open source Running microlink.io · unavatar.io Formerly @vercel ▲',
4747
image: 'https://pbs.twimg.com/profile_images/2000931726244106244/Ty7-KT2j_400x400.jpg',
@@ -57,7 +57,7 @@ Generated by [AVA](https://avajs.dev).
5757
> Snapshot 1
5858
5959
{
60-
author: '#!/kiko/beats (Kikobeats) on X',
60+
author: '#!/kiko/beats',
6161
date: null,
6262
description: 'engineering ▲ @vercel; founder of microlink.io teslahunt.io unavatar.io keyv.js.org osom.js.org browserless.js.org metascraper.js.org',
6363
image: 'https://pbs.twimg.com/profile_images/1846292082501054464/oKUC44PF_400x400.jpg',
@@ -73,7 +73,7 @@ Generated by [AVA](https://avajs.dev).
7373
> Snapshot 1
7474
7575
{
76-
author: 'Javi López ⛩️ (javilop)',
76+
author: 'Javi López ⛩️',
7777
date: '2025-08-11T16:31:12.000Z',
7878
description: 'Comparto tutoriales, herramientas y noticias de IA. Y también chorradas. Fundador @Magnific_AI (acq. por @freepik) 🗞️ Newsletter: https://t.co/tMELO1P8Wk',
7979
image: 'https://pbs.twimg.com/profile_images/1581679886267301888/BHGZpOc6_400x400.jpg',
@@ -89,7 +89,7 @@ Generated by [AVA](https://avajs.dev).
8989
> Snapshot 1
9090
9191
{
92-
author: 'Javi López ⛩️ (javilop) on X',
92+
author: 'Javi López ⛩️',
9393
date: null,
9494
description: 'Comparto tutoriales, herramientas y noticias de IA. Fundador @Magnific_AI 🔥 Guía IAs: https://t.co/JApwm5Tmfo 🗞️ Newsletter: https://t.co/tMELO1P8Wk',
9595
image: 'https://pbs.twimg.com/profile_images/1581679886267301888/BHGZpOc6_400x400.jpg',
@@ -105,9 +105,9 @@ Generated by [AVA](https://avajs.dev).
105105
> Snapshot 1
106106
107107
{
108-
author: null,
108+
author: 'Donald J. Trump',
109109
date: '2020-01-30T15:39:43.000Z',
110-
description: null,
110+
description: '“Schiff blasted for not focusing on California homeless.” @foxandfriends His District is in terrible shape. He is a corrupt pol who only dreams of the Impeachment Hoax. In my opinion he is mentally deranged!',
111111
image: 'https://abs.twimg.com/rweb/ssr/default/v2/og/image.png',
112112
lang: 'en',
113113
publisher: 'X',
@@ -121,14 +121,14 @@ Generated by [AVA](https://avajs.dev).
121121
> Snapshot 1
122122
123123
{
124-
author: 'SmartUA (UaSmart) on X',
124+
author: 'Donald J. Trump',
125125
date: null,
126-
description: 'Y terminamos el dia con Cultura de empresa con @patoroco, @flopezluis, Katia, Angélica en @codemotion_es #codemotion2017',
127-
image: 'https://pbs.twimg.com/media/DPadOKpXcAIL-NW.jpg:large',
126+
description: '“Schiff blasted for not focusing on California homeless.” @foxandfriends His District is in terrible shape. He is a corrupt pol who only dreams of the Impeachment Hoax. In my opinion he is mentally deranged!',
127+
image: 'https://pbs.twimg.com/profile_images/874276197357596672/kUuht00m_400x400.jpg',
128128
lang: 'en',
129129
publisher: 'X',
130130
title: '@realDonaldTrump on X',
131-
url: 'https://twitter.com/UaSmart/status/934106870834454529',
131+
url: 'https://twitter.com/realDonaldTrump/status/1222907250383245320',
132132
video: null,
133133
}
134134

@@ -137,9 +137,9 @@ Generated by [AVA](https://avajs.dev).
137137
> Snapshot 1
138138
139139
{
140-
author: 'Kiko Beats on X: “Experimenting with Clearbit API + Apple TV 3D Parallax https://t.co/Qsm163k4mJ https://t.co/5bcuqoEyAa”',
140+
author: 'Kiko Beats',
141141
date: '2017-06-28T19:01:34.000Z',
142-
description: null,
142+
description: 'Experimenting with Clearbit API + Apple TV 3D Parallax https://t.co/Qsm163k4mJ',
143143
image: 'https://abs.twimg.com/rweb/ssr/default/v2/og/image.png',
144144
lang: 'en',
145145
publisher: 'X',
@@ -153,7 +153,7 @@ Generated by [AVA](https://avajs.dev).
153153
> Snapshot 1
154154
155155
{
156-
author: '#!/kiko/beats (Kikobeats) on X',
156+
author: '#!/kiko/beats',
157157
date: null,
158158
description: 'Experimenting with Clearbit API + Apple TV 3D Parallax https://t.co/Qsm163k4mJ',
159159
image: 'https://pbs.twimg.com/tweet_video_thumb/DDbh3WCXYAAZfz9.jpg:large',
@@ -169,9 +169,9 @@ Generated by [AVA](https://avajs.dev).
169169
> Snapshot 1
170170
171171
{
172-
author: null,
172+
author: 'SmartUA',
173173
date: '2017-11-24T17:10:07.000Z',
174-
description: null,
174+
description: 'Y terminamos el dia con Cultura de empresa con @patoroco, @flopezluis, Katia, Angélica en @codemotion_es #codemotion2017 https://t.co/5fCDNpQh4D',
175175
image: 'https://abs.twimg.com/rweb/ssr/default/v2/og/image.png',
176176
lang: 'en',
177177
publisher: 'X',
@@ -185,7 +185,7 @@ Generated by [AVA](https://avajs.dev).
185185
> Snapshot 1
186186
187187
{
188-
author: 'SmartUA (UaSmart) on X',
188+
author: 'SmartUA',
189189
date: null,
190190
description: 'Y terminamos el dia con Cultura de empresa con @patoroco, @flopezluis, Katia, Angélica en @codemotion_es #codemotion2017',
191191
image: 'https://pbs.twimg.com/media/DPadOKpXcAIL-NW.jpg:large',
185 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)