Skip to content

Commit e4ede2d

Browse files
committed
fix(logo-favicon): expose resolveFaviconUrl
1 parent ec0de8b commit e4ede2d

File tree

3 files changed

+45
-30
lines changed

3 files changed

+45
-30
lines changed

packages/metascraper-logo-favicon/README.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,31 @@ $ npm install metascraper-logo-favicon --save
2020

2121
#### options
2222

23-
##### google
23+
##### favicon
2424

2525
Type: `boolean`<br>
2626
Default: `true`
2727

28-
It enables logo resolution using Google API.
28+
It tries to resolve `favicon.ico` of the url.
2929

30-
##### favicon
30+
##### google
3131

3232
Type: `boolean`<br>
3333
Default: `true`
3434

35-
It tries to resolve `favicon.ico` of the url.
35+
It enables logo resolution using Google API.
3636

37-
##### rootFavicon
37+
##### gotOpts
3838

39-
Type: `boolean`|`regexp`<br>
40-
Default: `true`
39+
Type: `object`
4140

42-
It tries to resolve `favicon.ico` of the url when the URL is a subdomain.
41+
Any option provided here will passed to [got#options](https://github.com/sindresorhus/got#options).
42+
43+
##### keyvOpts
44+
45+
Type: `object`
46+
47+
Any option provided here will passed to [@keyvhq/memoize#options](https://github.com/microlinkhq/keyv/tree/master/packages/memoize#keyvoptions).
4348

4449
##### pickFn
4550

@@ -68,17 +73,12 @@ Type: `function`
6873

6974
It will be used to determine if a favicon URL is valid.
7075

71-
##### gotOpts
72-
73-
Type: `object`
74-
75-
Any option provided here will passed to [got#options](https://github.com/sindresorhus/got#options).
76-
77-
##### keyvOpts
76+
##### rootFavicon
7877

79-
Type: `object`
78+
Type: `boolean`|`regexp`<br>
79+
Default: `true`
8080

81-
Any option provided here will passed to [@keyvhq/memoize#options](https://github.com/microlinkhq/keyv/tree/master/packages/memoize#keyvoptions).
81+
It tries to resolve `favicon.ico` of the url when the URL is a subdomain.
8282

8383
## License
8484

packages/metascraper-logo-favicon/src/index.d.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,38 @@ type Options = {
66
* @default true
77
*/
88
favicon?: boolean,
9-
/**
10-
* Enable favicon.ico using the root domain for subdomains
11-
* @default true
12-
*/
13-
rootFavicon?: boolean | RegExp,
9+
1410
/**
1511
* Enable retrieve logo from Google API.
1612
* @default true
1713
*/
1814
google?: boolean,
15+
1916
/**
2017
* https://github.com/sindresorhus/got#options
2118
*/
2219
gotOpts?: import('got').Options,
20+
2321
/**
2422
* https://github.com/microlinkhq/keyv/tree/master/packages/memoize#keyvoptions
2523
*/
2624
keyvOpts?: import('@keyvhq/core').Options<any>,
25+
2726
/**
2827
* The function to pick the favicon from the list of favicons.
2928
*/
3029
pickFn?: (sizes: DOMNOdeAtributes[]) => DOMNOdeAtributes,
30+
31+
/**
32+
* It will be used to determine if a favicon URL is valid.
33+
*/
34+
resolveFaviconUrl?: (faviconUrl: string, contentTypes: string[], gotOpts: import('got').Options) => boolean,
35+
36+
/**
37+
* Enable favicon.ico using the root domain for subdomains
38+
* @default true
39+
*/
40+
rootFavicon?: boolean | RegExp,
3141
}
3242

3343
declare function rules(options?: Options): import('metascraper').Rules;

packages/metascraper-logo-favicon/src/index.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ const defaultResolveFaviconUrl = async (faviconUrl, contentTypes, gotOpts) => {
160160
return response.url
161161
}
162162

163-
const createFavicon = (
164-
[ext, contentTypes],
165-
resolveFaviconUrl = defaultResolveFaviconUrl
166-
) => {
163+
const createFavicon = ([ext, contentTypes], resolveFaviconUrl) => {
167164
return async (url, { gotOpts } = {}) => {
168165
const faviconUrl = logo(`/favicon.${ext}`, { url })
169166
return faviconUrl
@@ -224,14 +221,21 @@ const createRootFavicon = ({ getLogo, withRootFavicon = true } = {}) => {
224221
}
225222

226223
module.exports = ({
227-
google: withGoogle = true,
228224
favicon: withFavicon = true,
229-
rootFavicon: withRootFavicon = true,
225+
google: withGoogle = true,
230226
gotOpts,
231227
keyvOpts,
232-
pickFn = pickBiggerSize
228+
pickFn = pickBiggerSize,
229+
resolveFaviconUrl = defaultResolveFaviconUrl,
230+
rootFavicon: withRootFavicon = true
233231
} = {}) => {
234-
const getLogo = createGetLogo({ withGoogle, withFavicon, gotOpts, keyvOpts })
232+
const getLogo = createGetLogo({
233+
gotOpts,
234+
keyvOpts,
235+
resolveFaviconUrl,
236+
withFavicon,
237+
withGoogle
238+
})
235239
const rootFavicon = createRootFavicon({ getLogo, withRootFavicon })
236240
return {
237241
logo: [
@@ -250,3 +254,4 @@ module.exports.createFavicon = createFavicon
250254
module.exports.createRootFavicon = createRootFavicon
251255
module.exports.createGetLogo = createGetLogo
252256
module.exports.pickBiggerSize = pickBiggerSize
257+
module.exports.resolveFaviconUrl = defaultResolveFaviconUrl

0 commit comments

Comments
 (0)