metascraper-x 5.49.9 → 5.49.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/index.js +38 -17
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "metascraper-x",
|
|
3
3
|
"description": "Metascraper integration with x.com",
|
|
4
4
|
"homepage": "https://github.com/microlinkhq/metascraper/packages/metascraper-x",
|
|
5
|
-
"version": "5.49.
|
|
5
|
+
"version": "5.49.11",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"author": {
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"test": "NODE_PATH=.. TZ=UTC ava --timeout 15s"
|
|
40
40
|
},
|
|
41
41
|
"license": "MIT",
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "33f9a40f8370cc12485388912c3a12e70c35e3b6"
|
|
43
43
|
}
|
package/src/index.js
CHANGED
|
@@ -25,30 +25,51 @@ const test = memoizeOne(url =>
|
|
|
25
25
|
['twitter.com', 'x.com'].includes(parseUrl(url).domain)
|
|
26
26
|
)
|
|
27
27
|
|
|
28
|
+
const getAuthorName = memoizeOne(ogTitle =>
|
|
29
|
+
ogTitle?.split(' on X:')[0].split(' (@')[0].trim()
|
|
30
|
+
)
|
|
31
|
+
|
|
28
32
|
module.exports = ({ resolveUrl = url => url } = {}) => {
|
|
29
33
|
const rules = {
|
|
30
34
|
author: [
|
|
31
|
-
toAuthor($ =>
|
|
32
|
-
|
|
33
|
-
return author?.includes(' on X') ? author.split(' on X')[0] : author
|
|
34
|
-
})
|
|
35
|
-
],
|
|
36
|
-
title: [
|
|
37
|
-
toTitle(
|
|
38
|
-
($, url) => `@${new URL(url).pathname.toString().split('/')[1]} on X`
|
|
35
|
+
toAuthor($ =>
|
|
36
|
+
getAuthorName($('meta[property="og:title"]').attr('content'))
|
|
39
37
|
)
|
|
40
38
|
],
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
title: [
|
|
40
|
+
toTitle(($, url) => {
|
|
41
|
+
const username = new URL(url).pathname.split('/')[1]
|
|
42
|
+
const authorName = getAuthorName(
|
|
43
|
+
$('meta[property="og:title"]').attr('content')
|
|
44
|
+
)
|
|
45
|
+
return authorName
|
|
46
|
+
? `${authorName} (@${username}) on X`
|
|
47
|
+
: `@${username} on X`
|
|
48
|
+
})
|
|
45
49
|
],
|
|
50
|
+
url: [toUrl($ => $('link[rel="canonical"]').attr('href'))],
|
|
46
51
|
description: [
|
|
47
52
|
toDescription(async $ => {
|
|
48
53
|
let description =
|
|
49
54
|
$jsonld('mainEntity.description')($) ||
|
|
50
55
|
$('meta[property="og:description"]').attr('content')
|
|
51
56
|
|
|
57
|
+
if (!description) {
|
|
58
|
+
const ogTitle = $('meta[property="og:title"]').attr('content')
|
|
59
|
+
if (ogTitle?.includes(' on X: "')) {
|
|
60
|
+
description = ogTitle.split(' on X: "')[1].split('" / X')[0]
|
|
61
|
+
const urls = getUrls(description)
|
|
62
|
+
if (urls.length > 1) {
|
|
63
|
+
const lastUrl = urls[urls.length - 1]
|
|
64
|
+
if (description.endsWith(lastUrl)) {
|
|
65
|
+
description = description.replace(lastUrl, '').trim()
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!description) return
|
|
72
|
+
|
|
52
73
|
const urls = getUrls(description)
|
|
53
74
|
const resolvedUrls = await Promise.all(urls.map(resolveUrl))
|
|
54
75
|
|
|
@@ -62,14 +83,14 @@ module.exports = ({ resolveUrl = url => url } = {}) => {
|
|
|
62
83
|
],
|
|
63
84
|
image: [
|
|
64
85
|
toImage($ => {
|
|
65
|
-
|
|
86
|
+
const imageUrl =
|
|
66
87
|
$jsonld('mainEntity.image.contentUrl')($) ||
|
|
88
|
+
$('video').attr('poster') ||
|
|
67
89
|
$('meta[property="og:image"]').attr('content')
|
|
68
90
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return imageUrl
|
|
91
|
+
return imageUrl?.endsWith('_200x200.jpg')
|
|
92
|
+
? imageUrl.replace('_200x200.jpg', '_400x400.jpg')
|
|
93
|
+
: imageUrl
|
|
73
94
|
})
|
|
74
95
|
],
|
|
75
96
|
date: [
|