您的位置:首页 > 编程语言

利用Octopress在github pages上搭建个人博客

2013-09-29 23:14 861 查看

利用Octopress在github pages上搭建个人博客

SEP 29TH, 2013

在GitHub Pages上用Octopress搭建博客,需要安装ruby环境、git环境等。本人在Fedora下成功搭建Octopress,这里把主要步骤和遇到的问题做一个记录。

在搭建的过程中发现yum安装的ruby与rake在管理octopress博客的时候会引起冲突,要使用rvm的方式安装ruby和rake;另外rvm一般用curl一段脚本来安装的话,网址有所变化,原来的教程中的网址要“去掉一个点”。

1.安装rvm
curl https://rawgithub.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable
网上很多教程用raw.github这个站点,但目前需要使用去除”.“的网址

2.将rvm命令添加到系统path中
echo ‘[[ -s “$HOME/.rvm/scripts/rvm” ]] && . “$HOME/.rvm/scripts/rvm” # Load RVM function’ >> ~/.bash_profile
source ~/.bash_profile
如果不做这一步,第3步的”rvm use 1.9.3”将不起作用

3.安装ruby1.9.3
rvm install 1.9.3 或者用2.0也可以
rvm use 1.9.3 或者用2.0也可以
这是下载ruby和rubygem源代码后本地自动编译安装.ruby和rubygem的版本要对应,这里会自动解决。

此时,可以查看ruby版本:ruby —version 我在shell下看到的是:ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]

4.确保你装了git
用git —version查看版本
如果没有安装git,那就sudo yum install git-core

5.下载octopress
不要认为是网页上的“下载”,这里是用git的方式:
cd ~/workspace/blog
git clone git://github.com/imathis/octopress.git octopress
如果下载速度超慢请尝试修改hosts

6.安装bundle
cd octopress
gem install bundler
bundle install
这里很奇怪,先前bundle的时候一直报错,换成ruby.taobao.org还是报错,但这次没有修改Gemfile竟然下载安装无阻。

7.安装主题
rake install [‘theme-name’]
如果只是rake install表示安装默认主题(位于octopress/.theme)
这里如果遭遇rake install aborted错误,说rake版本不正确,因为rvm帮我们下载了0.9的版本,但是如果用yum install的话装的是10.x的版本,需要先yum remove rake。。感觉ruby的包管理机制真烦。

8.后续操作
生成模板:
rake generate

本地预览:
rake preview
可以通过127.0.0.1的4000端口查看

添加新文章
rake new_post[“文章标题”] //可以直接输入中文,Octopress 自动将汉字转换成拼音url
例如:rake new_post[“hello”]
会在source/_post/生成hello.markdown的文件
用文本编辑器打开后编辑即可。

添加新页面
rake new_page[“about”]

其他的编辑项
blog的配置信息修改: _config.ym

9.部署到github
需要先在github上建立一个repo,名字格式为username.github.io
官方主页的说明https://help.github.com/articles/user-organization-and-project-pages

然后是rake setup_github_pages
会询问你的repo的地址,填写你刚刚建立的repo的全称。
如果使用git@的形式,需要github的ssh设定过,否则会报错:
ssh-keygen
文件名取为/home/username/.ssh/github
然后就生成了key,复制/home/username/.ssh/github.pub中的内容,粘贴到github上account setting中的ssh key里面就ok了。

然后是部署:
rake deploy
如果github上比本地版本高则部署会失败,可以修改Rakefile第264行,“#”前添加“+”即可

ok,查看一下,比如我的:zchrissirhcz.github.com
可以看到octopress已经在了!

10.域名绑定
官方的帮助:https://help.github.com/articles/setting-up-a-custom-domain-with-pages 比如在godaddy买了example.com域名,然后把A记录改为 204.232.175.78(git page) 然后在本地octopress/source目录下新建CNAME文件,填写example.com
据说国外DNS容易被墙,索性换成DNSPOD好了

总结:
新建文章:rake new_page[‘文章名’]
增删改查:在octopress/source/_posts中进行
生成:rake generate 预览:rake preview 部署:rake deploy

参考:
http://beyondvincent.com/blog/2013/08/03/108-creating-a-github-blog-using-octopress/ http://easypi.github.io/blog/2013/01/05/using-octopress-to-setup-blog-on-github/ http://ginsmile.github.io/blog/2013/08/29/octopressbo-ke-ji-qiao/#.UkfO2x0W1q8 http://beiyuu.com/github-pages/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: