Skip to content

Commit

Permalink
fix(logo-favicon): expose resolveFaviconUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jul 15, 2024
1 parent ec0de8b commit e4ede2d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 30 deletions.
34 changes: 17 additions & 17 deletions packages/metascraper-logo-favicon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,31 @@ $ npm install metascraper-logo-favicon --save

#### options

##### google
##### favicon

Type: `boolean`<br>
Default: `true`

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

##### favicon
##### google

Type: `boolean`<br>
Default: `true`

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

##### rootFavicon
##### gotOpts

Type: `boolean`|`regexp`<br>
Default: `true`
Type: `object`

It tries to resolve `favicon.ico` of the url when the URL is a subdomain.
Any option provided here will passed to [got#options](https://github.com/sindresorhus/got#options).

##### keyvOpts

Type: `object`

Any option provided here will passed to [@keyvhq/memoize#options](https://github.com/microlinkhq/keyv/tree/master/packages/memoize#keyvoptions).

##### pickFn

Expand Down Expand Up @@ -68,17 +73,12 @@ Type: `function`

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

##### gotOpts

Type: `object`

Any option provided here will passed to [got#options](https://github.com/sindresorhus/got#options).

##### keyvOpts
##### rootFavicon

Type: `object`
Type: `boolean`|`regexp`<br>
Default: `true`

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

## License

Expand Down
20 changes: 15 additions & 5 deletions packages/metascraper-logo-favicon/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,38 @@ type Options = {
* @default true
*/
favicon?: boolean,
/**
* Enable favicon.ico using the root domain for subdomains
* @default true
*/
rootFavicon?: boolean | RegExp,

/**
* Enable retrieve logo from Google API.
* @default true
*/
google?: boolean,

/**
* https://github.com/sindresorhus/got#options
*/
gotOpts?: import('got').Options,

/**
* https://github.com/microlinkhq/keyv/tree/master/packages/memoize#keyvoptions
*/
keyvOpts?: import('@keyvhq/core').Options<any>,

/**
* The function to pick the favicon from the list of favicons.
*/
pickFn?: (sizes: DOMNOdeAtributes[]) => DOMNOdeAtributes,

/**
* It will be used to determine if a favicon URL is valid.
*/
resolveFaviconUrl?: (faviconUrl: string, contentTypes: string[], gotOpts: import('got').Options) => boolean,

/**
* Enable favicon.ico using the root domain for subdomains
* @default true
*/
rootFavicon?: boolean | RegExp,
}

declare function rules(options?: Options): import('metascraper').Rules;
Expand Down
21 changes: 13 additions & 8 deletions packages/metascraper-logo-favicon/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ const defaultResolveFaviconUrl = async (faviconUrl, contentTypes, gotOpts) => {
return response.url
}

const createFavicon = (
[ext, contentTypes],
resolveFaviconUrl = defaultResolveFaviconUrl
) => {
const createFavicon = ([ext, contentTypes], resolveFaviconUrl) => {
return async (url, { gotOpts } = {}) => {
const faviconUrl = logo(`/favicon.${ext}`, { url })
return faviconUrl
Expand Down Expand Up @@ -224,14 +221,21 @@ const createRootFavicon = ({ getLogo, withRootFavicon = true } = {}) => {
}

module.exports = ({
google: withGoogle = true,
favicon: withFavicon = true,
rootFavicon: withRootFavicon = true,
google: withGoogle = true,
gotOpts,
keyvOpts,
pickFn = pickBiggerSize
pickFn = pickBiggerSize,
resolveFaviconUrl = defaultResolveFaviconUrl,
rootFavicon: withRootFavicon = true
} = {}) => {
const getLogo = createGetLogo({ withGoogle, withFavicon, gotOpts, keyvOpts })
const getLogo = createGetLogo({
gotOpts,
keyvOpts,
resolveFaviconUrl,
withFavicon,
withGoogle
})
const rootFavicon = createRootFavicon({ getLogo, withRootFavicon })
return {
logo: [
Expand All @@ -250,3 +254,4 @@ module.exports.createFavicon = createFavicon
module.exports.createRootFavicon = createRootFavicon
module.exports.createGetLogo = createGetLogo
module.exports.pickBiggerSize = pickBiggerSize
module.exports.resolveFaviconUrl = defaultResolveFaviconUrl

0 comments on commit e4ede2d

Please sign in to comment.