metascraper-iframe 5.24.9 → 5.25.3

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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "metascraper-iframe",
3
3
  "description": "Embed a representation of an URL on third party sites",
4
4
  "homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-iframe",
5
- "version": "5.24.9",
5
+ "version": "5.25.3",
6
6
  "main": "src/index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -24,8 +24,8 @@
24
24
  "oembed"
25
25
  ],
26
26
  "dependencies": {
27
- "@metascraper/helpers": "^5.24.9",
28
- "got": "~11.8.2",
27
+ "@metascraper/helpers": "^5.25.2",
28
+ "got": "~11.8.3",
29
29
  "lodash": "~4.17.21",
30
30
  "oembed-spec": "~1.3.20",
31
31
  "p-reflect": "~2.1.0"
@@ -54,5 +54,5 @@
54
54
  "slow": 300,
55
55
  "timeout": "120000"
56
56
  },
57
- "gitHead": "cc6de681c5c24bcd4944975cd6effbcfc6e2bd50"
57
+ "gitHead": "56854b5ace8ea093a45c37a1254fb3fa6266e84b"
58
58
  }
@@ -0,0 +1,32 @@
1
+ 'use strict'
2
+
3
+ const { normalizeUrl, memoizeOne } = require('@metascraper/helpers')
4
+ const { map } = require('lodash')
5
+
6
+ const getPlayerUrl = memoizeOne(
7
+ (url, $) =>
8
+ normalizeUrl(
9
+ url,
10
+ $('meta[name="twitter:player"]').attr('content') ||
11
+ $('meta[property="twitter:player"]').attr('content')
12
+ ),
13
+ memoizeOne.EqualityUrlAndHtmlDom
14
+ )
15
+
16
+ const fromTwitter = () => async ({ htmlDom, url, iframe }) => {
17
+ const playerUrl = getPlayerUrl(url, htmlDom)
18
+ if (!playerUrl) return
19
+
20
+ const props = [
21
+ 'frameborder="0"',
22
+ 'scrolling="no"',
23
+ ...map(iframe, (value, key) => `${key}="${value}"`)
24
+ ]
25
+
26
+ return `<iframe src="${playerUrl}" ${props.join(' ')}></iframe>`
27
+ }
28
+
29
+ fromTwitter.test = (...args) => !!getPlayerUrl(...args)
30
+
31
+ module.exports = fromTwitter
32
+ module.exports.getPlayerUrl = getPlayerUrl
package/src/index.js CHANGED
@@ -4,16 +4,20 @@ const { memoizeOne } = require('@metascraper/helpers')
4
4
 
5
5
  const fromProvider = require('./from-provider')
6
6
  const fromHTML = require('./from-html')
7
+ const fromTwitter = require('./from-twitter')
7
8
 
8
9
  const isValidUrl = memoizeOne(
9
- (url, $) => fromHTML.test(url, $) || fromProvider.test(url),
10
+ (url, $) =>
11
+ fromHTML.test(url, $) || fromProvider.test(url) || fromTwitter.test(url),
10
12
  memoizeOne.EqualityUrlAndHtmlDom
11
13
  )
12
14
 
13
15
  const test = ({ url, htmlDom }) => isValidUrl(url, htmlDom)
14
16
 
15
17
  module.exports = ({ gotOpts } = {}) => {
16
- const rules = { iframe: [fromHTML(gotOpts), fromProvider(gotOpts)] }
18
+ const rules = {
19
+ iframe: [fromHTML(gotOpts), fromProvider(gotOpts), fromTwitter(gotOpts)]
20
+ }
17
21
  rules.test = test
18
22
  return rules
19
23
  }