metascraper-logo-favicon 5.44.0 → 5.45.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/package.json +10 -3
- package/src/index.js +30 -13
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "metascraper-logo-favicon",
|
|
3
3
|
"description": "metascraper logo favicon fallback",
|
|
4
4
|
"homepage": "https://github.com/microlinkhq/metascraper/packages/metascraper-logo-favicon",
|
|
5
|
-
"version": "5.
|
|
5
|
+
"version": "5.45.0",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"author": {
|
|
@@ -25,11 +25,12 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@keyvhq/memoize": "~2.1.0",
|
|
28
|
-
"@metascraper/helpers": "^5.
|
|
28
|
+
"@metascraper/helpers": "^5.45.0",
|
|
29
29
|
"lodash": "~4.17.21",
|
|
30
30
|
"reachable-url": "~1.8.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
+
"async-listen": "latest",
|
|
33
34
|
"ava": "5"
|
|
34
35
|
},
|
|
35
36
|
"engines": {
|
|
@@ -42,5 +43,11 @@
|
|
|
42
43
|
"test": "NODE_PATH=.. TZ=UTC ava --timeout 15s"
|
|
43
44
|
},
|
|
44
45
|
"license": "MIT",
|
|
45
|
-
"
|
|
46
|
+
"ava": {
|
|
47
|
+
"files": [
|
|
48
|
+
"test/**/*.js",
|
|
49
|
+
"!test/helpers.js"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"gitHead": "590dfe76d57ff7d1a8829a279bb0575ed82eeba4"
|
|
46
53
|
}
|
package/src/index.js
CHANGED
|
@@ -107,15 +107,22 @@ const pickBiggerSize = async (sizes, { gotOpts } = {}) => {
|
|
|
107
107
|
pickBiggerSize.sortBySize = collection =>
|
|
108
108
|
orderBy(collection, ['size.priority'], ['desc'])
|
|
109
109
|
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
110
|
+
const createFavicon =
|
|
111
|
+
({ ext, contentTypes }) =>
|
|
112
|
+
async (url, { gotOpts } = {}) => {
|
|
113
|
+
const faviconUrl = logo(`/favicon.${ext}`, { url })
|
|
114
|
+
if (!faviconUrl) return undefined
|
|
115
|
+
|
|
116
|
+
const response = await reachableUrl(faviconUrl, gotOpts)
|
|
117
|
+
const contentType = response.headers['content-type']
|
|
118
|
+
|
|
119
|
+
const isValidContenType =
|
|
120
|
+
contentType && contentTypes.some(ct => contentType.includes(ct))
|
|
121
|
+
|
|
122
|
+
return isValidContenType && reachableUrl.isReachable(response)
|
|
123
|
+
? response.url
|
|
124
|
+
: undefined
|
|
125
|
+
}
|
|
119
126
|
|
|
120
127
|
const google = async (url, { gotOpts } = {}) => {
|
|
121
128
|
const response = await reachableUrl(google.url(url), gotOpts)
|
|
@@ -127,9 +134,19 @@ google.url = (url, size = 128) =>
|
|
|
127
134
|
|
|
128
135
|
const createGetLogo = ({ withGoogle, withFavicon, gotOpts, keyvOpts }) => {
|
|
129
136
|
const getLogo = async url => {
|
|
130
|
-
const providers = [
|
|
131
|
-
|
|
132
|
-
|
|
137
|
+
const providers = [
|
|
138
|
+
withFavicon &&
|
|
139
|
+
createFavicon({
|
|
140
|
+
ext: 'png',
|
|
141
|
+
contentTypes: ['image/png']
|
|
142
|
+
}),
|
|
143
|
+
withFavicon &&
|
|
144
|
+
createFavicon({
|
|
145
|
+
ext: 'ico',
|
|
146
|
+
contentTypes: ['image/vnd.microsoft.icon', 'image/x-icon']
|
|
147
|
+
}),
|
|
148
|
+
withGoogle && google
|
|
149
|
+
].filter(Boolean)
|
|
133
150
|
|
|
134
151
|
for (const provider of providers) {
|
|
135
152
|
const logoUrl = await provider(url, { gotOpts })
|
|
@@ -182,8 +199,8 @@ module.exports = ({
|
|
|
182
199
|
}
|
|
183
200
|
}
|
|
184
201
|
|
|
185
|
-
module.exports.favicon = favicon
|
|
186
202
|
module.exports.google = google
|
|
203
|
+
module.exports.createFavicon = createFavicon
|
|
187
204
|
module.exports.createRootFavicon = createRootFavicon
|
|
188
205
|
module.exports.createGetLogo = createGetLogo
|
|
189
206
|
module.exports.pickBiggerSize = pickBiggerSize
|