Skip to content

Commit

Permalink
Merge pull request #714 from microlinkhq/next
Browse files Browse the repository at this point in the history
fix(x): strip query parameter from title
  • Loading branch information
Kikobeats committed Jun 30, 2024
2 parents 85d3621 + 9fcf3d7 commit 6f4db22
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/metascraper-x/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ module.exports = ({ resolveUrls = false, resolveUrl = url => url } = {}) => {
return author?.includes(' on X') ? author.split(' on X')[0] : author
})
],
title: [toTitle(($, url) => `@${url.split('/')[3]} on X`)],
title: [
toTitle(
($, url) => `@${new URL(url).pathname.toString().split('/')[1]} on X`
)
],
url: [
toUrl($ =>
$('link[rel="canonical"]').attr('href')?.replace('twitter.com', 'x.com')
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-x/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const createMetascraper = (...args) =>
])

test('from a X profile', async t => {
const url = 'https://x.com/Kikobeats'
const url = 'https://x.com/kikobeats?mx=2'
const html = await readFile(resolve(__dirname, 'fixtures/profile.html'))
const metascraper = createMetascraper()
const metadata = await metascraper({ url, html })
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-x/test/snapshots/index.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Generated by [AVA](https://avajs.dev).
image: 'https://pbs.twimg.com/profile_images/1717583638991138816/4HvMeeps_400x400.jpg',
lang: 'en',
publisher: 'X',
title: '@Kikobeats on X',
title: '@kikobeats on X',
url: 'https://x.com/Kikobeats',
video: null,
}
Expand Down
Binary file modified packages/metascraper-x/test/snapshots/index.js.snap
Binary file not shown.

0 comments on commit 6f4db22

Please sign in to comment.