@@ -234,6 +234,7 @@ These plugins will not be shipped with **metascraper** by default and need to b
234
234
| Package | Version | Dependencies |
235
235
|--------|-------|------------|
236
236
| [`metascraper-clearbit-logo`](/packages/metascraper-clearbit-logo) | [](https://www.npmjs.com/package/metascraper-clearbit-logo) | [](https://david-dm.org/microlinkhq/metascraper?path=packages/metascraper-clearbit-logo) |
237
+ | [`metascraper-soundcloud`](/packages/metascraper-soundcloud) | [](https://www.npmjs.com/package/metascraper-soundcloud) | [](https://david-dm.org/microlinkhq/metascraper?path=packages/metascraper-soundcloud) |
237
238
238
239
# ## Write your own plugin
239
240
@@ -244,29 +245,21 @@ The following schema represents the API compromise that a plugin need to follow:
244
245
` ` ` js
245
246
'use strict'
246
247
247
- // ` opts` can be loaded using `.metascraperrc`
248
- // confguration file
248
+ // ` opts` can be loaded using `.metascraperrc` config file
249
249
module.exports = opts => {
250
- // define as `rule` as you want.
251
- // They receive as parameter :
252
- // - htmlDom : the cheerio HTML instance.
253
- // - url : The input URL used for extact the content.
254
- // - meta : The current state of the information detected.
255
- const rule = ({ htmlDom, meta, url : baseUrl }) => {
256
- // the logic for determinate if apply or not the rule.
257
- // just return the data that you want to be
258
- // assigned to the final output
259
- return !meta.name && 'hello world'
260
- }
261
-
262
- // Rules need to follow an `array` interface.
263
- const rules = [rule]
264
-
265
- // Need to assign a property name
266
- rules.propName = 'logo'
267
-
268
- // export the rules!
269
- return rules
250
+ // You can define as props as you want.
251
+ // props are organized based on an object key.
252
+ return ({
253
+ logo : [
254
+ // You can setup more than one rules per prop (priority is important!).
255
+ // They receive as parameter :
256
+ // - `htmlDom` : the cheerio HTML instance.
257
+ // - `url` : The input URL used for extact the content.
258
+ // - `meta` : The current state of the information detected.
259
+ ({ htmlDom : $, meta, url: baseUrl }) => wrap($ => $('meta[property="og:logo"]').attr('content')),
260
+ ({ htmlDom : $, meta, url: baseUrl }) => $('meta[itemprop="logo"]').attr('content')),
261
+ ]
262
+ })
270
263
}
271
264
```
272
265
0 commit comments