metascraper-manifest 5.29.13 → 5.30.0
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/index.js +27 -1
- package/package.json +4 -3
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
|
-
.
|
|
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.
|
|
5
|
+
"version": "5.30.0",
|
|
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.
|
|
27
|
+
"@metascraper/helpers": "^5.29.15",
|
|
28
28
|
"async-memoize-one": "~1.1.1",
|
|
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": "
|
|
46
|
+
"gitHead": "209dd1c7e760bb72f627e5af095de1e3cc322b7f"
|
|
46
47
|
}
|