metascraper-logo 5.36.0 → 5.37.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/README.md +20 -0
- package/index.js +26 -17
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -14,6 +14,26 @@
|
|
|
14
14
|
$ npm install metascraper-logo --save
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
### metascraper-logo([options])
|
|
20
|
+
|
|
21
|
+
#### options
|
|
22
|
+
|
|
23
|
+
##### filter
|
|
24
|
+
|
|
25
|
+
Type: `function`
|
|
26
|
+
|
|
27
|
+
A function to filter results in case it passes a test implemented by the provided function. It is the `url` as the first parameter:
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
const metascraper = require('metascraper')([
|
|
31
|
+
require('metascraper-logo')({
|
|
32
|
+
filter: url => url.endsWith('.png')
|
|
33
|
+
})
|
|
34
|
+
])
|
|
35
|
+
```
|
|
36
|
+
|
|
17
37
|
## License
|
|
18
38
|
|
|
19
39
|
**metascraper-logo** © [Microlink](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/metascraper/blob/master/LICENSE.md) License.<br>
|
package/index.js
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
const { $jsonld, url: urlFn, toRule } = require('@metascraper/helpers')
|
|
4
4
|
const { eq, get } = require('lodash')
|
|
5
5
|
|
|
6
|
-
const toUrl = toRule(urlFn)
|
|
7
|
-
|
|
8
6
|
const toLogoUrl = ($, propName) => {
|
|
9
7
|
const logo = $jsonld(propName)($)
|
|
10
8
|
const width = get(logo, 'width')
|
|
@@ -12,18 +10,29 @@ const toLogoUrl = ($, propName) => {
|
|
|
12
10
|
return width && height && eq(width, height) && get(logo, 'url')
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
module.exports = () =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
module.exports = ({ filter } = {}) => {
|
|
14
|
+
const mapper = filter
|
|
15
|
+
? async value => {
|
|
16
|
+
const result = urlFn(value)
|
|
17
|
+
return typeof result === 'string' ? await filter(result) : result
|
|
18
|
+
}
|
|
19
|
+
: urlFn
|
|
20
|
+
|
|
21
|
+
const toUrl = toRule(mapper)
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
logo: [
|
|
25
|
+
toUrl($ => $('meta[property="og:logo"]').attr('content')),
|
|
26
|
+
toUrl($ => $('meta[itemprop="logo"]').attr('content')),
|
|
27
|
+
toUrl($ => $('img[itemprop="logo"]').attr('src')),
|
|
28
|
+
toUrl($ => toLogoUrl($, 'brand.logo')),
|
|
29
|
+
toUrl($ => toLogoUrl($, 'organization.logo')),
|
|
30
|
+
toUrl($ => toLogoUrl($, 'place.logo')),
|
|
31
|
+
toUrl($ => toLogoUrl($, 'product.logo')),
|
|
32
|
+
toUrl($ => toLogoUrl($, 'service.logo')),
|
|
33
|
+
toUrl($ => toLogoUrl($, 'publisher.logo')),
|
|
34
|
+
toUrl($ => toLogoUrl($, 'logo.url')),
|
|
35
|
+
toUrl($ => toLogoUrl($, 'logo'))
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "metascraper-logo",
|
|
3
3
|
"description": "Get logo property from HTML markup",
|
|
4
4
|
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-logo",
|
|
5
|
-
"version": "5.
|
|
5
|
+
"version": "5.37.0",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"test": "exit 0"
|
|
36
36
|
},
|
|
37
37
|
"license": "MIT",
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "9e8942a59bfbdca300320de1ba1165a767c1f3e8"
|
|
39
39
|
}
|