Skip to content

Commit 9fcf3d7

Browse files
committed
fix(x): strip query parameter from title
1 parent 85d3621 commit 9fcf3d7

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

packages/metascraper-x/src/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ module.exports = ({ resolveUrls = false, resolveUrl = url => url } = {}) => {
3030
return author?.includes(' on X') ? author.split(' on X')[0] : author
3131
})
3232
],
33-
title: [toTitle(($, url) => `@${url.split('/')[3]} on X`)],
33+
title: [
34+
toTitle(
35+
($, url) => `@${new URL(url).pathname.toString().split('/')[1]} on X`
36+
)
37+
],
3438
url: [
3539
toUrl($ =>
3640
$('link[rel="canonical"]').attr('href')?.replace('twitter.com', 'x.com')

packages/metascraper-x/test/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const createMetascraper = (...args) =>
2121
])
2222

2323
test('from a X profile', async t => {
24-
const url = 'https://x.com/Kikobeats'
24+
const url = 'https://x.com/kikobeats?mx=2'
2525
const html = await readFile(resolve(__dirname, 'fixtures/profile.html'))
2626
const metascraper = createMetascraper()
2727
const metadata = await metascraper({ url, html })

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Generated by [AVA](https://avajs.dev).
1515
image: 'https://pbs.twimg.com/profile_images/1717583638991138816/4HvMeeps_400x400.jpg',
1616
lang: 'en',
1717
publisher: 'X',
18-
title: '@Kikobeats on X',
18+
title: '@kikobeats on X',
1919
url: 'https://x.com/Kikobeats',
2020
video: null,
2121
}
Binary file not shown.

0 commit comments

Comments
 (0)