1.0.0 • Public • Published

middleware-rename-file NPM version NPM monthly downloads NPM total downloads Linux Build Status

Middleware for renaming views based on front-matter properties.


Install with npm:

$ npm install --save middleware-rename-file

How it works

You can rename the destination path of a file using properties defined in its front-matter. Any of the path properties on a vinyl file should work.


Given the source file, scaffolds/layouts/base.hbs:

  basename: default.hbs
  dirname: templates
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    {% body %}

The generated destination path would be, templates/default.hbs.


This can be used with assemble, verb, generate, update or an other library that is based on templates.


The main export is a middleware function that should be passed to .onLoad to ensure that files are renamed as early in the render cycle as possible (so that when rendering begins, the actual file names are available on the context).

var rename = require('middleware-rename-file');
var assemble = require('assemble');
var app = assemble();
app.onLoad(/\.md$/, rename());

In addition to the regex provided to .onLoad, you may also optionally pass a filter function to rename():


Don't modify a file with the name (stem) index:

app.onLoad(/\.md$/, rename(function(file) {
  return file.stem !== 'index';


Related projects

  • assemble: Get the rocks out of your socks! Assemble makes you fast at creating web projects… more | homepage
  • generate: Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… more | homepage
  • templates: System for creating and managing template collections, and rendering templates with any node.js template engine… more | homepage
  • update: Be scalable! Update is a new, open source developer framework and CLI for automating updates… more | homepage
  • verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… more | homepage


Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test


Jon Schlinkert


Copyright © 2017, Jon Schlinkert. MIT

This file was generated by verb-generate-readme, v0.4.2, on February 01, 2017.

Package Sidebar


npm i middleware-rename-file

Weekly Downloads






Last publish


  • jonschlinkert