Metalsmith plugin for globally replacing strings
npm install metalsmith-text-replacemetalsmith.json. For example:
json
{
"plugins": {
"metalsmith-text-replace": {
"/": {
"find": "cat",
"replace": "dog"
}
}
}
}
`
Note that when applied this way, only string can be passed as arguments.
For Metalscript's JavaScript API, metalsmith-text-replace can be used like any
other plugin, by attaching it to the function invocation chain on the
Metalscript object. For example:
`js
var replace = require('metalsmith-text-replace');
require('metalsmith')(__dirname)
.use(replace({
'/': {
find: /cat/gi,
replace: "dog"
}
})
.build();
`
You can also provide an array if you want to replace multiple strings in the
same match:
`js
var replace = require('metalsmith-text-replace');
require('metalsmith')(__dirname)
.use(replace({
'/': [
{
find: /cat/gi,
replace: "dog"
},
{
find: /foobar/g,
replace: function(match) { return match.toUpperCase(); }
}
]
})
.build();
`
Options
You can pass additional options to minimatch using the options` property.