Skip to content

Commit e37a4ee

Browse files
committed
Add plugins documentation
1 parent 6feef00 commit e37a4ee

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,40 @@ These plugins will not be shipped with **metascraper** by default and need to b
225225

226226
## Write your own plugin
227227

228-
Write your own plugin is the way to easily extend **metascraper** functionality.
228+
A plugin is the simplest way for extending **metascraper** functionality.
229229

230-
*SOON*
230+
The following schema represents the API compromise that a plugin need to follow:
231+
232+
```js
233+
'use strict'
234+
235+
// `opts` can be loaded using `.metascraperrc`
236+
// confguration file
237+
module.exports = opts => {
238+
// define as `rule` as you want.
239+
// They receive as parameter:
240+
// - htmlDom: the cheerio HTML instance.
241+
// - url: The input URL used for extact the content.
242+
// - meta: The current state of the information detected.
243+
const rule = ({ htmlDom, meta, url: baseUrl }) => {
244+
// the logic for determinate if apply or not the rule.
245+
// just return the data that you want to be
246+
// assigned to the final output
247+
return !meta.name && 'hello world'
248+
}
249+
250+
// Rules need to follow an `array` interface.
251+
const rules = [rule]
252+
253+
// Need to assign a property name
254+
rules.propName = 'logo'
255+
256+
// export the rules!
257+
return rules
258+
}
259+
```
260+
261+
We recommend check [core plugins packages](/packages) as examples to understand better how to connect your code with **metascraper** plugins.
231262

232263
## API
233264

0 commit comments

Comments
 (0)