{"id":15732581,"url":"https://github.com/jonschlinkert/middleware-rename-file","last_synced_at":"2025-08-17T10:33:41.297Z","repository":{"id":57296853,"uuid":"64751178","full_name":"jonschlinkert/middleware-rename-file","owner":"jonschlinkert","description":"Middleware for templates, assemble, verb, generate or update, for renaming files based on front-matter properties.","archived":false,"fork":false,"pushed_at":"2017-02-01T18:29:31.000Z","size":11,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-17T10:32:47.115Z","etag":null,"topics":["filepath","path","rename","rewrite"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonschlinkert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-02T11:28:06.000Z","updated_at":"2021-04-12T22:32:25.000Z","dependencies_parsed_at":"2022-09-01T06:40:21.157Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/middleware-rename-file","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/jonschlinkert/middleware-rename-file","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fmiddleware-rename-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fmiddleware-rename-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fmiddleware-rename-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fmiddleware-rename-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/middleware-rename-file/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fmiddleware-rename-file/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270837403,"owners_count":24654374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filepath","path","rename","rewrite"],"created_at":"2024-10-04T00:21:02.031Z","updated_at":"2025-08-17T10:33:41.228Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# middleware-rename-file [![NPM version](https://img.shields.io/npm/v/middleware-rename-file.svg?style=flat)](https://www.npmjs.com/package/middleware-rename-file) [![NPM monthly downloads](https://img.shields.io/npm/dm/middleware-rename-file.svg?style=flat)](https://npmjs.org/package/middleware-rename-file)  [![NPM total downloads](https://img.shields.io/npm/dt/middleware-rename-file.svg?style=flat)](https://npmjs.org/package/middleware-rename-file) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/middleware-rename-file.svg?style=flat\u0026label=Travis)](https://travis-ci.org/jonschlinkert/middleware-rename-file)\n\n\u003e Middleware for renaming views based on front-matter properties.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save middleware-rename-file\n```\n\n## How it works\n\nYou can rename the destination path of a file using properties defined in its front-matter. Any of the path properties on a [vinyl](https://github.com/gulpjs/vinyl) file should work.\n\n**Example**\n\nGiven the source file, `scaffolds/layouts/base.hbs`:\n\n```html\n---\nrename:\n  basename: default.hbs\n  dirname: templates\n---\n\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003ctitle\u003e{{title}}\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    {% body %}\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nThe generated destination path would be, `templates/default.hbs`.\n\n## Usage\n\nThis can be used with [assemble](https://github.com/assemble/assemble), [verb](https://github.com/verbose/verb), [generate](https://github.com/generate/generate), [update](https://github.com/update/update) or an other library that is based on [templates](https://github.com/jonschlinkert/templates).\n\n**.onLoad**\n\nThe 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).\n\n```js\nvar rename = require('middleware-rename-file');\nvar assemble = require('assemble');\nvar app = assemble();\n\napp.onLoad(/\\.md$/, rename());\n```\n\nIn addition to the regex provided to `.onLoad`, you may also optionally pass a filter function to `rename()`:\n\n**Example**\n\nDon't modify a file with the name (stem) `index`:\n\n```js\napp.onLoad(/\\.md$/, rename(function(file) {\n  return file.stem !== 'index';\n}));\n```\n\n## About\n\n### Related projects\n\n* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble \"Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit\")\n* [generate](https://www.npmjs.com/package/generate): Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… [more](https://github.com/generate/generate) | [homepage](https://github.com/generate/generate \"Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the robustness and configurability of Yeoman, the expressiveness and simplicity of Slush, and more powerful flow control and composability than either.\")\n* [templates](https://www.npmjs.com/package/templates): System for creating and managing template collections, and rendering templates with any node.js template engine… [more](https://github.com/jonschlinkert/templates) | [homepage](https://github.com/jonschlinkert/templates \"System for creating and managing template collections, and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator or blog framework.\")\n* [update](https://www.npmjs.com/package/update): Be scalable! Update is a new, open source developer framework and CLI for automating updates… [more](https://github.com/update/update) | [homepage](https://github.com/update/update \"Be scalable! Update is a new, open source developer framework and CLI for automating updates of any kind in code projects.\")\n* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb \"Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.\")\n\n### Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n### Building docs\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n### Running tests\n\nRunning 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:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n### Author\n\n**Jon Schlinkert**\n\n* [github/jonschlinkert](https://github.com/jonschlinkert)\n* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)\n\n### License\n\nCopyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).\nMIT\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.2, on February 01, 2017._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fmiddleware-rename-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fmiddleware-rename-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fmiddleware-rename-file/lists"}