hexo-console-rename
Version:
Hexo console plug-in to rename post file according to its title
128 lines (90 loc) • 4.58 kB
Markdown
hexo-console-rename [![NPM version][npm-image]][npm-url] [![Dependency Status][depstat-image]][depstat-url]
===================
> [Hexo] console plug-in to rename post file according to its title, if asset folder is also renamed if exsits
Install using [npm][npm-url].
For hexo 2.x
$ npm install hexo-console-rename@2 --save
For hexo 3.x
$ npm install hexo-console-rename@3 --save
To know more about this plug-in, check out this [post].
```
$ hexo rename source/_post/some_post_with_wrong_file_name.md
[] source/_post/some_post_with_wrong_file_name.md
[] source/_post/some_post_with_wrong_file_name.md -> source/_post/new_file_name_from_title.md
[] source/_post/some_post_with_wrong_file_name -> source/_post/new_file_name_from_title
```
**IMPORTANT TIP** Commit all your files into git before excute this command
```
$ hexo r source/**/*.md
[] source/_drafts/name.md
[] source/_posts/2014-08-18-name.md
[] source/_posts/codepen.md
[] source/_posts/image.md
[] source/_posts/cool_post.md
[] source/_posts/new_post.md
[] source/_drafts/name.md -> source/_drafts/name-is-cool.md
[] source/_posts/2014-08-18-name.md -> source/_posts/2014-08-18-name-is-something-really-cool.md
[] source/_drafts/name -> source/_drafts/name-is-cool
[] source/_posts/2014-08-18-name -> source/_posts/2014-08-18-name-is-something-really-cool
```
When no arg is passed, it is equals to `hexo rename source/_posts/*.*`
```
$ hexo rename
[find] source/_posts/2014-03-02-new_post.md
[find] source/_posts/2014-08-18-name.md
[rename] source/_posts/2014-08-18-name.md -> source/_posts/2014-08-18-name-is-something-really-cool.md
[rename] source/_posts/2014-08-18-name -> source/_posts/2014-08-18-name-is-something-really-cool
```
## Advanced Usage
`hexo-console-rename` can be used not only sync file name with `title`, it does more.
### Synchronize TimeStamp in Filename
If you have `timestamp` in your file name, then if you updated the `date` field in your front-matter. You'll probably wish to update the file name also.
`hexo-console-rename` can help you on this.
**IMPORTANT TIP** Commit all your files into git before excute this command
```
$ hexo r source/**/*.md
[] source/_posts/2014-08-18-name.md
[] source/_posts/codepen.md
[] source/_posts/image.md
[] source/_posts/cool_post.md
[] source/_posts/new_post.md
[] source/_posts/2014-08-18-name.md -> source/_posts/2014-08-19-name.md
[] source/_posts/2014-08-18-name -> source/_posts/2014-08-19-name
```
Suppose you update the `new_post_name` field in your `_config.yml`, then you might wish to migrate all post to fit the new name pattern.
`hexo-console-rename` can help you on this. You need to specify the old pattern with `--old-permalink` (`-p` for short), then all post will be migrated automatically.
Suppose you changed `new_post_name` from `:title.md` to `:year-:month-:day-:title.md`.
**IMPORTANT TIP** Commit all your files into git before excute this command
```
$ hexo r -p ':title.md' source/**/*.md
[] source/_posts/2014-08-17-codepen.md
[] source/_posts/2014-08-18-name-is-something-really-cool.md
[] source/_posts/2014-08-19-name-is-cool.md
[] source/_posts/image.md
[] source/_posts/post.md
[] source/_posts/cool-post.md
[] source/_posts/image.md -> source/_posts/2014-08-15-image.md
[] source/_posts/cool-post.md -> source/_posts/2014-08-15-post.md
[] source/_posts/.md -> source/_posts/2014-08-15-cool-post.md
[] source/_posts/image -> source/_posts/2014-08-15-image
[] source/_posts/post -> source/_posts/2014-08-15-post
[] source/_posts/cool-post -> source/_posts/2014-08-15-cool-post
```
MIT
[![NPM downloads][npm-downloads]][npm-url]
[]: https://github.com/timnew/hexo-console-rename
[]: https://npmjs.org/package/hexo-console-rename
[]: http://img.shields.io/npm/v/hexo-console-rename.svg?style=flat
[]: http://img.shields.io/npm/dm/hexo-console-rename.svg?style=flat
[]: https://gemnasium.com/timnew/hexo-console-rename
[]: http://img.shields.io/gemnasium/timnew/hexo-console-rename.svg?style=flat
[]: http://hexo.io/
[]: http://timnew.dev/blog/2014/08/19/Hexo-plug-in-to-rename-the-post-according-to-title-automatically/