metalsmith-renamer
Advanced tools
Comparing version
@@ -8,15 +8,19 @@ 'use strict'; | ||
return function(files, metalsmith, done) { | ||
var matcher = minimatch.Minimatch(options.pattern); | ||
Object.keys(options).forEach(function(opt) { | ||
var matcher = minimatch.Minimatch(options[opt].pattern); | ||
Object.keys(files).forEach(function (file) { | ||
if (!matcher.match(file)) return; | ||
files[file].path.name = options.rename; | ||
files[file].path.base = options.rename; | ||
var renamedEntry = files[file].path.dir + "/" + options.rename; | ||
files[renamedEntry] = files[file]; | ||
delete files[file]; | ||
Object.keys(files).forEach(function(file) { | ||
if (!matcher.match(file)) { | ||
return; | ||
} | ||
files[file].path.name = options[opt].rename; | ||
files[file].path.base = options[opt].rename; | ||
var renamedEntry = files[file].path.dir + "/" + options[opt].rename; | ||
files[renamedEntry] = files[file]; | ||
delete files[file]; | ||
}); | ||
}); | ||
done(); | ||
}; | ||
} |
{ | ||
"name": "metalsmith-renamer", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Plugin to take a pattern and rename each matched file", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# metalsmith-renamer | ||
This is a plugin for [Metalsmith](http://www.metalsmith.io) that renames files matching a given `pattern` | ||
This is a plugin for [Metalsmith](http://www.metalsmith.io) that renames files matching a given `pattern`. | ||
Presently it only accepts files, not folders, but folder renaming is planned for the near future. | ||
## Usage | ||
If using the CLI for Metalsmith, metalsmith-renamer can be used like any other plugin by including it in `metalsmith.json`. For example: | ||
If using the CLI for Metalsmith, metalsmith-renamer can be used like any other plugin by including it in `metalsmith.json`. For example: | ||
@@ -13,4 +14,10 @@ ```json | ||
"metalsmith-renamer": { | ||
"pattern": "folder/*.md", | ||
"rename": "folder/newName.md" | ||
"filesToRename": { | ||
"pattern": "folder/**/*.md", | ||
"rename": "newName.md" | ||
}, | ||
"moreFiles": { | ||
"pattern": "folder/about.html", | ||
"rename": "index.html" | ||
} | ||
} | ||
@@ -27,7 +34,13 @@ } | ||
.use(renamer({ | ||
pattern: 'folder/*.md', | ||
rename: 'folder/newName.md' | ||
} | ||
}) | ||
.build(); | ||
filesToRename: { | ||
pattern: 'folder/**/*.md', | ||
rename: 'newName.md' | ||
}, | ||
moreFiles: { | ||
pattern: 'folder/about.html', | ||
rename: 'index.html' | ||
}, //and as many more patterns as you want | ||
} | ||
}) | ||
.build(); | ||
``` | ||
@@ -43,3 +56,3 @@ | ||
- I use it to simulate [metalsmith-permalinks](https://github.com/segmentio/metalsmith-permalinks) partially by renaming certain files `index.html`, allowing me to link straight to directories and not have to use the filename. metalsmith-permalink insists on enclosing files within a structured folder system, whereas I have folder already organized manually. | ||
- Use it to rename folder names for preprocessor stylesheets, allowing you to keep a Stylus/SCSS/Less folder in your `src` folder, and then rename it to `css` in production build. | ||
<!-- - Use it to rename folder names for preprocessor stylesheets, allowing you to keep a Stylus/SCSS/Less folder in your `src` folder, and then rename it to `css` in production build. --> | ||
@@ -49,3 +62,5 @@ | ||
## Roadmap | ||
- v0.1 ~~Core renaming functionality~~ | ||
- v0.2: Allow specifying multiple inputs, avoiding the need to call the plugin multiple times. | ||
- [x] v0.1 Core renaming functionality | ||
- [x] v0.2 Allow specifying multiple inputs, avoiding the need to call the plugin multiple times. | ||
- [ ] v0.3 Allow renaming of directories. | ||
- [ ] v0.4 Clean up declaration method to take named objects, or a single unnamed one. |
5040
14.49%21
23.53%63
31.25%