主要环境:nodeJs, git,hexo

NodeJs

安装:https://nodejs.org/en

Git

  1. 安装:https://git-scm.com
  2. 生成公钥,供后面的github账号使用
1
2
3
4
5
6
7
8
9
# 中括号为需要替换的内容 [你的用户名] => zfd
git config --global user.name [你的用户名]
git config --global user.email [你的邮箱]
ssh-keygen -t rsa -C [你的邮箱]

# 进入{home_dir}/.ssh
cd
cd .ssh
cat id_rsa.pub

Github设置

添加ssh keys

主页->点击头像->setting->SSH keys->Add new,把上面的git本地公钥复制到key里面,写个title保存即可。
添加认证后,hexo可以自动提交到github.

新建repo

新建一个repo,注意名称一定是username.github.io这样的格式,默认访问url:https://username.github.io

Hexo

安装

安装hexo:

1
2
npm install -g hexo-cli
npm install -g hexo-server

进入项目目录,安装其他:

1
npm install

安装hexo-theme-indigo主题:https://github.com/yscoder/hexo-theme-indigo/wiki/%E5%AE%89%E8%A3%85

相关命令:https://hexo.io/zh-cn/docs/setup.html

1
2
hexo new page tags
hexo new page categories

本地看效果:

1
2
hexo clean && hexo g
hexo server

提交github

1
hexo d

写作

你可以执行下列命令来创建一篇新文章。
您可以在命令中指定文章的布局(layout),默认为 post,可以通过修改 _config.yml 中的 default_layout 参数来指定默认布局。

1
hexo new [layout] <title>

https://hexo.io/zh-cn/docs/writing.html

一键部署、提交

设置git alias

1
git config --global alias.blog '!hexo g && hexo d && git pull && git add -A && git commit -m "blog update" && git push origin master'

一键提交2个github项目

1
git blog

注:第一次提交先单独push一次,因为会有账号密码验证。

最终成果

blogServer project:https://github.com/zfd/blogServer
blog project:https://github.com/zfd/zfd.github.io
blog url: https://zfd.github.io