metascraper-x 5.55.0 → 5.56.2

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/index.js +6 -12
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "metascraper-x",
3
3
  "description": "Metascraper rules for X (Twitter) posts — author, text, media, and engagement metadata.",
4
4
  "homepage": "https://github.com/microlinkhq/metascraper/packages/metascraper-x",
5
- "version": "5.55.0",
5
+ "version": "5.56.2",
6
6
  "types": "src/index.d.ts",
7
7
  "main": "src/index.js",
8
8
  "author": {
@@ -31,7 +31,7 @@
31
31
  "x"
32
32
  ],
33
33
  "dependencies": {
34
- "@metascraper/helpers": "5.55.0"
34
+ "@metascraper/helpers": "5.56.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "ava": "8"
@@ -46,5 +46,5 @@
46
46
  "test": "NODE_PATH=.. TZ=UTC ava --timeout 15s"
47
47
  },
48
48
  "license": "MIT",
49
- "gitHead": "c6fdffea348dcee4ff5ce22613518c4c68f50f2a"
49
+ "gitHead": "63168a1c6ab9fa67552a13fd9e4a60ad4c10f953"
50
50
  }
package/src/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const {
4
4
  $jsonld,
5
+ $meta,
5
6
  author,
6
7
  date,
7
8
  description,
@@ -31,17 +32,11 @@ const getAuthorName = memoizeOne(ogTitle =>
31
32
 
32
33
  module.exports = ({ resolveUrl = url => url } = {}) => {
33
34
  const rules = {
34
- author: [
35
- toAuthor($ =>
36
- getAuthorName($('meta[property="og:title"]').attr('content'))
37
- )
38
- ],
35
+ author: [toAuthor($ => getAuthorName($meta('og:title')($)))],
39
36
  title: [
40
37
  toTitle(($, url) => {
41
38
  const username = new URL(url).pathname.split('/')[1]
42
- const authorName = getAuthorName(
43
- $('meta[property="og:title"]').attr('content')
44
- )
39
+ const authorName = getAuthorName($meta('og:title')($))
45
40
  return authorName
46
41
  ? `${authorName} (@${username}) on X`
47
42
  : `@${username} on X`
@@ -51,11 +46,10 @@ module.exports = ({ resolveUrl = url => url } = {}) => {
51
46
  description: [
52
47
  toDescription(async $ => {
53
48
  let description =
54
- $jsonld('mainEntity.description')($) ||
55
- $('meta[property="og:description"]').attr('content')
49
+ $jsonld('mainEntity.description')($) || $meta('og:description')($)
56
50
 
57
51
  if (!description) {
58
- const ogTitle = $('meta[property="og:title"]').attr('content')
52
+ const ogTitle = $meta('og:title')($)
59
53
  if (ogTitle?.includes(' on X: "')) {
60
54
  description = ogTitle.split(' on X: "')[1].split('" / X')[0]
61
55
  const urls = getUrls(description)
@@ -90,7 +84,7 @@ module.exports = ({ resolveUrl = url => url } = {}) => {
90
84
  $('[data-testid="tweetPhoto"] img').attr('src') ||
91
85
  /* embebbed image from a link */
92
86
  $('[data-testid="card.layoutLarge.media"] img').attr('src') ||
93
- $('meta[property="og:image"]').attr('content')
87
+ $meta('og:image')($)
94
88
 
95
89
  return imageUrl?.endsWith('_200x200.jpg')
96
90
  ? imageUrl.replace('_200x200.jpg', '_400x400.jpg')