hexo安装、下载使用butterfly主题、部署到GiThub
安装前提:
-
注册github
-
安装git
-
安装node.js
一、安装hexo
1、建立一个文件夹 Blog(可以自己取名字),进入文件夹标右键打开 Git Bush Here,输入npm命令安装Hexo:
npm install -g hexo-cli
2、安装完成后,输入 hexo init 命令初始化博客:
hexo init
3、静态部署
hexo g #静态部署
hexo s #启动
访问 http://localhost:4000 查看
二、安装butterfly主题
1、在hexo项目根目录下执行操作clone主题
git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
2、如果沒有 pug 以及 stylus 的渲染器,还需要下载,否则在项目运行时会报错:
npm install hexo-renderer-pug hexo-renderer-stylus --save
3、修改项目根目录下的_config.yml文件(称为站点配置文件),开启主题
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
#theme: landscape
theme: butterfly
4、升级建议
为了減少升级主题带来的不便,我们还需要做以下操作:
把主题文件夹中的 _config.yml
复制到 Hexo 根目录下,同重命名为 _config.butterfly.yml
三、将Hexo部署到GiThub
1.绑定GitHub
(1)输入 ssh 命令,查看本机是否安装 SSH:
ssh
(2)已安装 SSH
输入 ssh-keygen -t rsa 指定 RSA 算法生成密钥,然后一路回车键,之后就就会生成两个文件,分别为秘钥 id_rsa 和公钥 id_rsa.pub.
注意观察 .ssh文件夹的生成位置
(3)在github上添加ssh公钥
复制公钥 id_rsa.pub 文件里的内容,进入我们的 GitHub 主页,先点击右上角,再点击 settings,先点击 SSH and GPG keys,再点击 New SSH key 添加
(4)通过在 Git Bash 中输入命令进行检验是否成功
ssh -T git@github.com
2、部署到GiThub
(1)打开根目录下的 _config.yml文件夹,在文件底部添加内容
deploy:
type: git
repository: https://github.com/xxx/xxx.github.io.git #你的仓库地址
branch: master
(2)回到 Blog 文件夹中,打开 Git Bash,安装Git部署插件
npm install hexo-deployer-git --save
(3)继续输入命令
hexo clean #清除缓存文件 db.json 和已生成的静态文件 public
hexo g #生成网站静态文件到默认设置的 public 文件夹(hexo generate 的缩写)
hexo d #自动生成网站静态文件,并部署到设定的仓库(hexo deploy 的缩写)
完成以后,输入 https://xxx.github.io 访问查看(xxx是你的github用户名)
出现连接ssh错误,无法部署到github时,参考文章 :连接github报错