# 前言
方便以后 CtrlCV,就写下这篇文章
# 安装 Git
因为最早的 Git 是在 linux 上编写开发,只需要一行代码即可
yum install git | |
git --version |
# 安装 Nodejs
Hexo 是基于 nodejs 编写,所以需要安装一下 nodejs 和 npm。嘻嘻,本 blog 有详细教程,这一步略过
安装完成后,检查版本
node -v | |
npm -v |
# 安装 hexo
npm install -g hexo-cli | |
hexo -v |
至此就全部安装完了,接下来初始化后安装 npm 依赖包
node_modules
: 依赖包public
;存放生成的页面scaffolds
;生成文章的一些模板source
:用来存放你的文章themes
:主题_config.yml
: 博客配置文件
hexo init myblog | |
cd myblog | |
npm install |
启动服务并且可以预览,歧视部署在服务器上没多大必要预览
hexo g | |
hexo serve |
# 创建仓库
创建和用户名相同的仓库,用户名后面加上 .github.io
,例如: yourname.github.io
这样做,GitHub page 才会被识别。如果用户名有大写,这里仓库名用小写
# 生成 SSH 添加到 GitHub
git config --global user.name "yourname" | |
git config --global user.email "youremail" |
以下命令可以检查是否输入正确
git config user.name | |
git config user.email |
创建 SSH 密钥回车 3 次
ssh-keygen -t rsa -C "youremail" |
以下命令可以查看是否成功
ssh -T git@github.com |
点击获取
id_rsa.pub 是私人秘钥,id_rsa.pub 是公共秘钥。保存路径为 /root/.ssh/id_rsa.pub
把公钥设置在 GitHub 上,这样当你连接 GitHub 自己的账户时,它就会根据公钥匹配你本地私钥,当能够相互匹配时,才能够顺利的通过 git 上传你的文件到 GitHub 上
# 将 hexo 部署到 GitHub
在站点配置文件 /myblog/_config.yml
底部添加修改
deploy: | |
type: git | |
repo: https://github.com/YourName/YourName.github.io.git | |
branch: master |
安装 deploy-git ,能用命令部署到 GitHub
npm install hexo-deployer-git --save |
至此,访问 GitHub Pages 托管网站即可看到你的博客了
hexo clean && hexo g && hexo d |