metascraper-manifest 5.29.15 → 5.30.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/index.js +27 -1
  2. package/package.json +5 -4
package/index.js CHANGED
@@ -2,10 +2,22 @@
2
2
 
3
3
  const { normalizeUrl, logo, composeRule } = require('@metascraper/helpers')
4
4
  const asyncMemoizeOne = require('async-memoize-one')
5
+ const dataUriToBuffer = require('data-uri-to-buffer')
5
6
  const { chain, toLower } = require('lodash')
6
7
  const memoize = require('@keyvhq/memoize')
8
+
7
9
  const got = require('got')
8
10
 
11
+ const parseSize = str => {
12
+ const parse = Number(
13
+ chain(str)
14
+ .split('x')
15
+ .first()
16
+ .value()
17
+ )
18
+ return Number.isNaN(parse) ? 0 : parse
19
+ }
20
+
9
21
  const createFetchManifest = ({ gotOpts, keyvOpts } = {}) => {
10
22
  const fetchManifest = async manifestUrl => {
11
23
  try {
@@ -30,6 +42,16 @@ module.exports = opts => {
30
42
  const toManifest = ($, url) => {
31
43
  const manifestUrl = $('link[rel="manifest"]').attr('href')
32
44
  if (!manifestUrl) return
45
+
46
+ if (manifestUrl.startsWith('data')) {
47
+ try {
48
+ const result = JSON.parse(dataUriToBuffer(manifestUrl))
49
+ return result
50
+ } catch (_) {
51
+ return undefined
52
+ }
53
+ }
54
+
33
55
  return fetchManifest(normalizeUrl(url, manifestUrl))
34
56
  }
35
57
 
@@ -41,11 +63,13 @@ module.exports = opts => {
41
63
  publisher: manifest({ from: 'short_name', to: 'publisher' }),
42
64
  logo: async ({ htmlDom, url }) => {
43
65
  const manifest = await toManifest(htmlDom, url)
66
+ if (!manifest) return
44
67
 
45
68
  const iconSrc = chain(manifest)
46
69
  .get('icons')
47
70
  .filter(icon => toLower(icon.purpose) !== 'monochrome')
48
- .orderBy('sizes', 'desc')
71
+ .map(props => Object.assign(props, { size: parseSize(props.sizes) }))
72
+ .orderBy('size', 'desc')
49
73
  .first()
50
74
  .get('src')
51
75
  .value()
@@ -54,3 +78,5 @@ module.exports = opts => {
54
78
  }
55
79
  }
56
80
  }
81
+
82
+ module.exports.parseSize = parseSize
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "metascraper-manifest",
3
3
  "description": "Metascraper integration for detecting PWA Web app manifest",
4
4
  "homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-manifest",
5
- "version": "5.29.15",
5
+ "version": "5.30.2",
6
6
  "main": "index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -24,8 +24,9 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "@keyvhq/memoize": "~1.6.14",
27
- "@metascraper/helpers": "^5.29.15",
28
- "async-memoize-one": "~1.1.1",
27
+ "@metascraper/helpers": "^5.30.2",
28
+ "async-memoize-one": "~1.1.2",
29
+ "data-uri-to-buffer": "~3.0.1",
29
30
  "got": "~11.8.5",
30
31
  "lodash": "~4.17.21"
31
32
  },
@@ -42,5 +43,5 @@
42
43
  "test": "NODE_PATH=.. TZ=UTC ava --timeout 15s"
43
44
  },
44
45
  "license": "MIT",
45
- "gitHead": "e58e9a45bdbb474198f0d4f3100fdae17729ea44"
46
+ "gitHead": "eaa06fb835f16ba5090ea3dc1b86e9e6389671b5"
46
47
  }