set-up-personal-blog-on-GitHub

准备

GitHub账号、Ubuntu系统

安装git

1
sudo apt-get install git

配置账户信息

1
2
git config --global user.email "you@example.com" # 你在GitHub上注册的email
git config --global user.name "Your Name"

check this: https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-%E5%AE%89%E8%A3%85-Git

安装NodeJS

1
wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh

安装完成后,重启终端并执行下列命令。

1
2
3
4
export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node
nvm install --lts
npm config set registry=https://registry.npm.taobao.org
npm install -g hexo-cli

check this: https://hexo.io/zh-cn/docs/index.html

建站

1
2
3
hexo init hexo # if error, check this: https://github.com/hexojs/hexo/issues/580
cd hexo
npm install

check this: https://hexo.io/zh-cn/docs/setup.html

安装NexT主题

1
2
cd hexo
git clone https://github.com/iissnan/hexo-theme-next themes/next

check this: http://theme-next.iissnan.com/getting-started.html

创建GitHub仓库

仓库名必须为:你的GitHub账号名.github.io
得到生成的仓库的链接,如:https://github.com/aeiouaoeiuv/aeiouaoeiuv.github.io.git

hexo部署

先修改_config.yml,修改如下:

1
2
3
deploy:
type: git
repo: https://github.com/aeiouaoeiuv/aeiouaoeiuv.github.io.git

然后执行如下命令:

1
2
3
4
cd hexo
npm install hexo-deployer-git --save
npm install hexo-generator-searchdb --save # 这个搜索功能所依赖的
hexo deploy

输入账号和密码,稍等片刻即可通过 你的账号名.github.io 访问博客了。

check this: https://hexo.io/zh-cn/docs/deployment.html#Git

换电脑怎么办?

在GitHub上新建一个repository,名为 hexo ,拷贝该url
在ubuntu上clone该repository,如: git clone git@github.com:aeiouaoeiuv/hexo.git hexo.git
然后把你的 hexo 里所有文件拷贝至该 hexo.git 目录,如: cp -rf hexo/* hexo.git

然后执行如下命令:

1
2
3
4
5
cd hexo.git
rm -rf themes/next/.git # 注意删掉此.git目录,否则next目录不会上传
git add .
git commit -m "comments"
git push origin master

新电脑操作步骤

1
2
3
git clone git@github.com:aeiouaoeiuv/hexo.git hexo.git
cd hexo.git
npm install # 没有npm?那就看上面的安装NodeJS吧。

以后写文章步骤

1
2
3
4
5
6
cd hexo.git
hexo clean # 最好clean一下,貌似不clean提交的还是旧的内容(虽然hexo server看到的是新的)
git add .
git commit -m "comments"
git push origin master
hexo deploy

git官方文档:https://git-scm.com/book/zh/v2
hexo官方文档:https://hexo.io/zh-cn/docs/
NexT主题官方文档:http://theme-next.iissnan.com/getting-started.html
NexT主题官方文档:https://theme-next.js.org/docs/