mac 环境重建hexo

换了Mac,重新记载一下搭建过程。

需要注意的是由于这种部署方法相当于重新搭建一个新的博客,在关联github后以前那些文章的md文件都会在repository清空,所以事先需要把repo里的文章下载备份一下。以及自己之前 Hexo文件夹内下载的主题和_config.xml文件都需要拷贝过来,这样才能无痛迁移。

下载brew
1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
下载git
1
brew install git
下载nodejs
1
brew install node
安装hexo
1
sudo npm install -g hexo

初始化,终端cd到一个指定的目录(~/Documents/hexo)执行如下命令:

1
hexo init ~/Documents/hexo

终端cd到hexo目录下,安装npm

1
npm install
关联已有的github

在finder中打开hexo创建文件夹下的_config.yml配置文件,拉到最底下修改成这样:

1
2
3
4
deploy:
type: git
repository: https://github.com/witchyang/witchyang.github.io.git
branch: master

在hexo文件夹目录下执行

1
hexo g

如果报错,则执行:

1
npm install hexo --save

再执行命令

1
hexo d

如果报错,则执行:

1
npm install hexo-deployer-git --save

然后再执行hexo g和hexo d. 此时终端会提示输入github的用户名和密码,输入完成后就已经成功链接了github上的repository,这时浏览器输入witchyang.github.io就可以看到博客页面了。

如果觉得对您有帮助,就扫我交个朋友吧!