metascraper-manifest 5.26.2 → 5.28.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.
- package/README.md +7 -7
- package/index.js +25 -18
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -17,17 +17,17 @@ $ npm install metascraper-manifest --save
|
|
|
17
17
|
|
|
18
18
|
#### options
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
##### gotOpts
|
|
21
|
+
|
|
22
|
+
Type: `object`
|
|
21
23
|
|
|
22
24
|
Any option provided here will passed to [got#options](https://github.com/sindresorhus/got#options).
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
##### keyvOpts
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
```
|
|
28
|
+
Type: `object`
|
|
29
|
+
|
|
30
|
+
Any option provided here will passed to [@keyvhq/memoize#options](https://github.com/microlinkhq/keyv/tree/master/packages/memoize#keyvoptions).
|
|
31
31
|
|
|
32
32
|
## License
|
|
33
33
|
|
package/index.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { logo, composeRule
|
|
3
|
+
const { normalizeUrl, logo, composeRule } = require('@metascraper/helpers')
|
|
4
4
|
const asyncMemoizeOne = require('async-memoize-one')
|
|
5
|
-
const { first, orderBy } = require('lodash')
|
|
5
|
+
const { get, first, orderBy } = require('lodash')
|
|
6
|
+
const memoize = require('@keyvhq/memoize')
|
|
6
7
|
const got = require('got')
|
|
7
8
|
|
|
8
|
-
const createFetchManifest = ({ gotOpts } = {}) =>
|
|
9
|
-
|
|
10
|
-
const manifest = $('link[rel="manifest"]').attr('href')
|
|
11
|
-
if (!manifest) return undefined
|
|
12
|
-
const manifestUrl = absoluteUrl(url, manifest)
|
|
9
|
+
const createFetchManifest = ({ gotOpts, keyvOpts } = {}) => {
|
|
10
|
+
const fetchManifest = async manifestUrl => {
|
|
13
11
|
try {
|
|
14
12
|
const { body: manifest } = await got(manifestUrl, {
|
|
15
13
|
...gotOpts,
|
|
@@ -17,26 +15,35 @@ const createFetchManifest = ({ gotOpts } = {}) =>
|
|
|
17
15
|
})
|
|
18
16
|
return manifest
|
|
19
17
|
} catch (_) {}
|
|
20
|
-
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return asyncMemoizeOne(
|
|
21
|
+
memoize(fetchManifest, keyvOpts, {
|
|
22
|
+
value: value => (value === undefined ? null : value)
|
|
23
|
+
})
|
|
24
|
+
)
|
|
25
|
+
}
|
|
21
26
|
|
|
22
27
|
module.exports = opts => {
|
|
23
28
|
const fetchManifest = createFetchManifest(opts)
|
|
24
|
-
|
|
29
|
+
|
|
30
|
+
const toManifest = ($, url) => {
|
|
31
|
+
const manifestUrl = $('link[rel="manifest"]').attr('href')
|
|
32
|
+
if (!manifestUrl) return undefined
|
|
33
|
+
return fetchManifest(normalizeUrl(url, manifestUrl))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const manifest = composeRule(toManifest)
|
|
25
37
|
|
|
26
38
|
return {
|
|
27
39
|
lang: manifest({ from: 'lang' }),
|
|
28
40
|
description: manifest({ from: 'description' }),
|
|
29
41
|
publisher: manifest({ from: 'short_name', to: 'publisher' }),
|
|
30
42
|
logo: async ({ htmlDom, url }) => {
|
|
31
|
-
const manifest = await
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (!icon) return
|
|
36
|
-
|
|
37
|
-
const { src: srcUrl } = icon
|
|
38
|
-
const iconUrl = absoluteUrl(url, srcUrl)
|
|
39
|
-
return logo(iconUrl)
|
|
43
|
+
const manifest = await toManifest(htmlDom, url)
|
|
44
|
+
const icons = get(manifest, 'icons')
|
|
45
|
+
const icon = first(orderBy(icons, 'sizes', 'desc')) || {}
|
|
46
|
+
return logo(icon.src, { url })
|
|
40
47
|
}
|
|
41
48
|
}
|
|
42
49
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "metascraper-manifest",
|
|
3
3
|
"description": "Metascraper integration for derecting PWA Web app manifest",
|
|
4
4
|
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-manifest",
|
|
5
|
-
"version": "5.
|
|
5
|
+
"version": "5.28.2",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"pwa"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@
|
|
26
|
+
"@keyvhq/memoize": "~1.6.6",
|
|
27
|
+
"@metascraper/helpers": "^5.28.2",
|
|
27
28
|
"async-memoize-one": "~1.1.0",
|
|
28
29
|
"got": "~11.8.3",
|
|
29
30
|
"lodash": "~4.17.21"
|
|
@@ -50,5 +51,5 @@
|
|
|
50
51
|
"slow": 300,
|
|
51
52
|
"timeout": "120000"
|
|
52
53
|
},
|
|
53
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "373d7f2b46ca3d1f163c412c1735daaf9434568d"
|
|
54
55
|
}
|