hexo3.0迁移
##起因
因为折腾多平台部署,以为是hexo
版本过低,所以升级了hexo
到了3.0版本。结果却发现hexo d
和hexo g
等命令都失效了。运行会有类似提示
1 | Commands: |
##尝试官方迁移方案
由Hexo2.X –> Hexo3.0,官方给出了具体的升级方案。
但是我在升级的时候遇到了几个问题
- 连接npm速度慢
- 安装Hexo其他插件位置不当
之后我放弃了官方的解决方案。自己尝试从头开始
##自己的解决方案
从头开始并不是把之前的博文都删掉。而是重新建立一个文件夹,运行hexo init
后将原来的文章和.git文件复制过来。
切换淘宝npm镜像
连接npm国外镜像速度太慢,解决方案是切换npm的镜像。在npm的目录下找到.npmrc添加以下代码1
registry = https://registry.npm.taobao.org
安装Hexo命令行
1
C:\Users>npm install hexo-cli -g
新建文件夹
这里为文件夹的名字为test1
2
3
4
5C:\Users>F:
F:\>mkdir test
F:\>cd test初始化目录
使用hexo init
初始化目录即可1
F:\test>hexo init
初始化成功后会有类似提示
INFO Copying data to F:\test
INFO You are almost done! Don’t forget to run ‘npm install’ before you start bl
ogging with Hexo!安装相应的插件
Hexo3.0最大的变化是将很多原来的功能都独立成了插件。这里的插件有文章生成插件,部署插件等。根据上面的提示使用npm install
即可。1
F:\test>npm install
等待一段时间后,所有插件会自动下载完毕。如果出现一下类似提示请重新运行
npm install
直至不再提示npm ERR! registry error parsing json
npm install
完成后node_modules的文件夹结构应该是这样的。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18node_modules
├─hexo
│
├─hexo-generator-archive
│
├─hexo-generator-category
│
├─hexo-generator-index
│
├─hexo-generator-tag
│
├─hexo-renderer-ejs
│
├─hexo-renderer-marked
│
├─hexo-renderer-stylus
│
└─hexo-server复制原来的文章和主题当前文件夹
如果你有使用git管理整个网站的习惯还可以将原来的.git文件夹复制过来。但是请不要直接将原来的_config.yaml复制过来。而是用到的内容才复制生成静态文件和运行博客
1
F:\test>hexo g
运行完成,生成网页成功以下类似提示
INFO Files loaded in 3.6 s
INFO Generated: js/script.js
INFO Generated: fancybox/jquery.fancybox.pack.js
INFO Generated: fancybox/jquery.fancybox.js
…
INFO Generated: archives/2015/index.html
INFO Generated: archives/2015/07/index.html
INFO Generated: index.html
INFO 28 files generated in 1.32 s使用
hexo s
运行博客1
F:\test>hexo s
运行成功有以下类似提示
INFO Hexo is running at http://0.0.0.0:4000/. Press Ctrl+C to stop.
使用浏览器打开
http://localhost:4000
查看博客。Hello World Again!如果运行
hexo s
出现hexo
的帮助页面。也就是类似下面的提示1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26Usage: hexo <command>
Commands:
clean Removed generated files and cache.
config Get or set configurations.
deploy Deploy your website.
generate Generate static files.
help Get help on a command.
init Create a new Hexo folder.
list List the information of the site
migrate Migrate your site from other system to Hexo.
new Create a new post.
publish Moves a draft post from _drafts to _posts folder.
render Render files with renderer plugins.
version Display version information.
Global Options:
--config Specify config file instead of using _config.yml
--cwd Specify the CWD
--debug Display all verbose messages in the terminal
--draft Display draft posts
--safe Disable all plugins and scripts
--silent Hide output on console
For more help, you can use 'hexo help [command]' for the detailed information
or you can check the docs: http://hexo.io/docs/请使用
npm install hexo-server --save
安装hexo
服务器。类似的如果运行命令没有得到应有的效果。请安装对应的插件。以下是一些常用的插件列表安装命令
1
2
3
4
5
6
7
8
9npm install hexo-server --save @安装hexo 服务器
npm install hexo-deployer-git --save @安装hexo git部署插件
npm install hexo-deployer-heroku --save @安装hexo heroku 部署插件
npm install hexo-deployer-rsync --save @安装hexo同步插件
npm install hexo-deployer-openshift --save @不知道什么鬼
npm install hexo-renderer-marked@0.2 --save @安装hexo markdown渲染插件
npm install hexo-renderer-stylus@0.2 --save @安装hexo 模板插件
npm install hexo-generator-feed@1 --save @安装hexo RSS插件
npm install hexo-generator-sitemap@1 --save @安装hexo站点地图插件