Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。
环境准备
我使用的是Windows
平台。
安装Node.JS
安装GIT
安装Hexo
打开Git Bash
或者Git Shell
,如果是第一次使用Git,首先使用下面两条命令:
$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"
记录名字和邮箱;接着输入npm
命令安装Hexo:
npm install hexo-cli -g
npm install hexo --save
Hexo初始化
在建立好的目录里,进行初始化,我使用的是Git Bash,在该文件夹右键会看到Git Bash Here
,输入
hexo init
npm install
至此,Hexo已经建立好了博客。
写博客
hexo n "文章标题"
Hexo会创建好.md
文件,可以去.\source\_posts
目录下找到,进行编辑,Markdown编辑器推荐使用MarkdownPad2。
相关Markdown教程:Markdown入门学习小结。
本地预览
npm install hexo-server --save
安装Hexo-server插件,可以使用
hexo g
#生成
hexo s
#启动本地服务器
可以打开浏览器输入http://127.0.0.1:4000
,查看效果。
将本地博客部署到Github
- 首先注册一个『GitHub』帐号
- 建立与账户名对应的仓库,仓库名必须为your_user_name.github.com』或your_user_name.github.io』
- 添加SSH公钥到『Account settings -> SSH Keys -> Add SSH Key』
生成密钥:
ssh-keygen -t rsa -C "email@example.com"
Generating public/private rsa key pair.
Enter file in which to save the key (//.ssh/id_rsa): H:\git\myssh\ssh #可以直接Enter
Enter passphrase (empty for no passphrase): #输入密码,也可以不输入
Enter same passphrase again:
Your identification has been saved in H:\git\myssh\ssh.
Your public key has been saved in H:\git\myssh\ssh.pub.
key fingerprint is:
b0:0c:2e:67:33:ab:c1:50:10:40:0a:ba:c1:80:59:22 email@example.com
将密钥添加到Github:
用文本编辑器打开ssh.pub文件,拷贝其中的内容,将其添加到Add SSH Key
然后使用
ssh -T git@github.com
验证连接情况;至此Github端配置好了。接下来修改Hexo的配置,打开_config.yml
文件,修改Deployment项
deploy:
type: git
repository: git@github.com:topit/topit.github.io.git#输入Github仓库地址
branch: master
然后执行命令:
npm install hexo-deployer-git --save #安装git支持
至此所以配置均已做好,只需要执行
hexo g#生成
hexo d#部署
就完成了博客的创建。