hexo + github 搭建blog
网络上,随便搜一下hexo、github等关键词,就能出来一大堆相当详尽的博客搭建介绍,
我也是一步步跟着做下来,本文主要记录一些自己碰到的问题。
安装
- 安装Node.js和git,这里不再赘述
检查npm是不是在PATH下面
1$ which npm安装hexo
1$ npm install -g hexo-cli转圈圈运行之后,报错
123456npm ERR! registry error parsing jsonnpm ERR! Linux 2.6.32-358.el6.x86_64npm ERR! argv "<nodejs-dir>/bin/node" "<nodejs-dir>/bin/npm" "install" "-g" "hexo-cli"npm ERR! node v0.12.6npm ERR! npm v2.11.2npm ERR! Unexpected end of input可能是被墙了,加一个国内的源
123$ npm config set registry https://registry.npm.taobao.org// or edit ~/.npmrc, put the following line into it// registry = https://registry.npm.taobao.org现在就可以顺利安装了。
创建blog
在github上建一个名为blog的repo,然后clone到本地,在gh-pages分枝上建立
project page的方式来存放自己的blog1234567$ git clone https://github.com/niaokedaoren/blog.git$ cd blog$ git checkout --orphan gh-pages$ git rm -rf .$ git add .$ git commit -m "initial commit"$ git push origin gh-pages报错:
error: src refspec github-pages does not match any.
error: failed to push some refs to ‘https://github.com/niaokedaoren/blog.git‘
解决: push不能为空1234$ touch README$ git add .$ git commit -m "add dummy README"$ git push origin gp-pages上传一个rsa public key到github,可以实现无密钥登陆。
hexo建立blog
123$ hexo init blog$ cd blog$ npm install生成blog并启动hexo server,可以在 http://localhost:4000访问blog
12$ hexo g$ hexo s配置_config.yml
- deploy1234deploy:type: gitrepo: ssh://git@github.com/niaokedaoren/blog.gitbranch: gh-pages
注意: 如果这里repo写成https://github.com/niaokedaoren/blog.git
就会报错:pushing-to-git-returning-error-code-403-fatal-http-request-failed- url12url: http://niaokedaoren.github.io/blogroot: /blog/
否则部署到github上会无法加载css
- deploy
选择主题
我选择的是jacman
12$ cd <blog-dir>$ git clone https://github.com/wuchong/jacman.git themes/jacman可以注册一个多说,在themes/jacman/_config.yml配置一下多说shortname。
常用的命令
123456$ hexo new "post name" #写新的博客$ hexo new draft "draft name" #写博客草稿, scaffolds目录下可以编辑layout$ hexo clean #清理生成的页面$ hexo g$ hexo s$ hexo d
写作工具
我用的是sublime text2,具体配置参考http://www.jianshu.com/p/378338f10263
参考