Hexo搭建


1、安装Node.js

 官网:https://nodejs.org/zh-cn/

​ 建议使用 Node.js 10.0 及以上版本,最新版本貌似和hexo5有冲突。

​ 一路next傻瓜操作

2、安装hexo

cmd输入

1
npm install -g hexo-cli

3、建站

Github Page配置参见官网:https://pages.github.com/

记得本地hexo仓库要关联到github page

1
git remote add origin github.com/你的github名字/你的github名字.github.io.git

新建hexo文件夹,打开git bash,一步步输入

1
2
3
4
5
6
7
8
9
10
//初始化
hexo init
//安装依赖
npm install
//生成文件
hexo g
//开启服务
hexo s
//本地启动
http://localhost:4000

大功告成,放个鞭炮庆祝下吧!


编写博客

进入hexo文件夹,打开git bash输入

1
hexo new post XXX

会在source文件中生成XXX.md,通过Typora打开编辑

1
2
3
hexo g
hexo s
hexo d

生成并发布

本地 :http://localhost:4000

外网 :https://你的github名字.github.io/

我的:cooper12138.github.io/

配置主题


用我的主题为例:butterfly

进入hexo文件夹,打开git bash

1
git clone -b master https://github.com/jerryc127/hexo -theme -butterfly .git themes/butterfly

把下载下来的文件名改成butterfly,并剪切到Hexo\themes文件夹中

修改站点配置文件_config.yml,把主题改为butterfly

1
theme:  butterfly

安装插件

1
npm install hexo -renderer -pug hexo -renderer -stylus - -save

各种疑难杂症的报错请自行百度!

重启试试,大功告成,放个鞭炮庆祝下吧!


git配置多账号

1、桌面右键打开git bash, 查看全局配置

1
2
3
git config --global --list
git config --global --unset user.name "你的名字"
git config --global --unset user.email "你的邮箱"

2、为不同账户配置ssh密钥

1
2
3
cd ~/.ssh    # cd到当前用户的.ssh文件夹
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitee -C "注册gitee邮箱" #为不同秘钥指定名称
ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "注册github邮箱"

完成后会在~/.ssh / 目录下生成以下文件:

  • id_rsa.github
  • id_rsa.github.pub
  • id_rsa.gitee
  • id_rsa.gitee.pub

复制公钥分别在github和gitee中设置

例如:

打开github设置

复制用户ssh文件夹中id_rsa.github.pub文件内容

保存

添加新的私钥

1
2
3
$ ssh-agent bash
$ ssh-add ~/.ssh/id_rsa.github
$ ssh-add ~/.ssh/id_rsa.gitee

3、进行全局配置

1
2
3
4
5
6
7
8
9
10
11
12
13
touch ~/.ssh/config    

# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa.gitee

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa.github

4、测试链接

1
2
3
4
5
6
7
$ ssh -T git@github.com
Hi cooper12138! You've successfully authenticated, but GitHub does not provide shell access.

zzc@DESKTOP-Q0N2LCT MINGW64 ~/.ssh
$ ssh -T git@gitee.com
Hi 章志成! You've successfully authenticated, but GITEE.COM does not provide shell access.

5、hexo博客仓库

1
2
3
4
5
6
vi .depoly_git/.git/config 增加

[user]
name = username
email = email

6、针对不同的本地仓库

增加本地配置,在每个仓库的.git/config中进行配置不同的用户,以及其他的配置信息

1
2
$ git config --local user.name 'github/gitee账号名'
$ git config --local user.email 'github/gitee账号邮箱'

–global是在全局配置文件中设置

–local 是针对当前仓库的项目进行设置

完工!