在Mac上从零开始搭建基于Github的Octopress博客

来源:互联网 发布:java的缺点知乎 编辑:程序博客网 时间:2024/06/05 00:20

Mac 上 octopress 安装失败了,后来只得在Windows下使用,主要是Mac 下terminal不太熟悉,还需要补课。

Windows 参考 http://opoo.org/octopress/

Mac rudy uninstall: http://dev.enekoalonso.com/2011/08/09/uninstalling-brew-so-i-can-reinstall/

http://stackoverflow.com/questions/2591501/how-to-uninstall-ruby-from-usr-local


最后,经过4~5个小时的不断尝试Mac上重要可以用Octopress 3.0了,原来是ruby的版本问题,用ruby2.0以上的版本一直装不上,而最后用1.9.3-p551则成功了。

终于有点小小的成就感了~ 

bundle install的时候常常出现错误,主要的问题是bundle不能安装在/usr/bin 目录下面,否则会出错。可以cd 到/usr/local 下bundle install, 可是不知道安装到哪个路径下去了。但是不会出错。

1.安装Octopress

确保安装了gitruby1.9.3,通过brew安装rbenv然后用rbenv安装ruby

安装brew ( http://brew.sh/ 直接用homebrew的命令行安装

curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz –strip 1 -C /usr/localexport PATH=/usr/local/bin:$PATH

安装成功后通过brew install查看brew版本

安装ruby

brew install rbenvbrew install ruby-buildrbenv install 1.9.3-p0rbenv rehash

最后安装Octopress

git clone git://github.com/imathis/octopress.git octopresscd octopressgem install bundlerrbenv rehashbundle installrake install

配置Octopress

编辑 config.yml文件的url,title,subtitle,author

最好把里面的twitter相关的信息全部删掉,否则由于GFW的原因,将会造成页面load很慢。同理,修改定制文件/source/_includes/custom/head.html 把google的自定义字体去掉。

安装支持新浪微博和Dribbble的Octopress的Greyshade主题

我现在用的就是greyshade主题 http://www.sgxiang.com

 cd octopress git clone git@github.com:allenhsu/greyshade.git .themes/greyshade echo "\$greyshade: color;" >> sass/custom/_colors.scss //替换 color 为自定义的链接高亮颜色 rake "install[greyshade]"

在_config.yml中加入

weibo_user: xsxiang # 微博数字 ID 或域名 IDdribbble_user: weibo_share: true # 是否开启微博分享按钮

关于greyshade主题的头像问题,有两种途径可以设置头像

  • 在_config.yml文件中设置一个email,然后到gravatar网站上添加该email并上传一张头像
  • 将需要使用的图片放到/source/images下。然后把/source/_includes/header.html文件中的img替换成 《img alt=“Profile Picture” src=“/images/tx.png” style=“width:160px;”》

配置Disqus插件

Disqus是octopress内置的comments功能,编辑config.yml文件可以打开该功能,找到以下内容修改

#Disqus commentsdisqus_short_name: disqus_show_comment_count: false

填入注册disqus账号的名称,并将false修改为true。【disqus要和自己的username.github.com关联上】

2.配置github相关

在本机创建ssh

cd ~/.sshssh-keygen -t rsa -C 你注册github时的email

弹出Enter file in which to save the key (/Users/twer/.ssh/id_rsa):直接按空格

弹出Enter passphrase (empty for no passphrase):输入你github账号的密码。Enter same passphrase again:再次输入你的密码。

打开~/.ssh下的id_rsa.pub文件复制里面的全部内容。
登陆github,选择Account Settings-->SSH Public Keys 添加ssh,把剪切板的内容复制到key输入框内直接保存。

测试shh:

ssh git@github.com

输出

PTY allocation request failed on channel 0Hi username! You've successfully authenticated, but GitHub does not provide shell access.Connection to github.com closed.

代表成功

建立一个仓库

登陆github创建一个仓库 ,仓库名称为username.github.com比如我的是sgxiang.github.com

3.部署博客到github

利用octopress的一个配置rake任务来自动配置上面创建的仓库:可以让我们方便的部署GitHub page。在终端输入如下命令:

rake setup_github_pages

弹出之后输入git@github.com:your_username/your_username.github.com.git不要用提示的io,我的是git@github.com/sgxiang/sgxiang.github.com.git

输入以下命令部署博客

rake generaterake deploy

如果无法push到仓库的master分支,尝试在项目目录的.git/config中添加

[branch "master"] remote = origin merge = refs/heads/master

博客的source需要单独提交,执行如下命令就可以将source提交到仓库的source分支下

git add .git commit -m 'Initial source commit'git push origin source

部署前可以在本地预览,输入rake preview之后在浏览器输入http://localhost:4000/来访问

4.写博客

通过命令

rake new_post["myTitle"]

文章生成在目录下的source/_posts目录下。文章是markdown格式的。可以通过 Mou 软件来编辑保存。

关于markdown的格式可以参考这篇文章:http://wowubuntu.com/markdown/

写完后就可以部署更新文章到github上了

rake generategit add .git commit -am "Some comment here." git push origin sourcerake deploy

参考文章

  • http://m.blog.csdn.net/blog/duck_genuine/7736037
  • http://www.imallen.com/blog/2013/10/16/deploying-octopress-to-qiniu.html
  • http://beyondvincent.com/blog/2013/08/03/108-creating-a-github-blog-using-octopress/
  • http://blog.devtang.com/blog/2012/02/10/setup-blog-based-on-github/
  • http://www.imallen.com/blog/2013/05/12/add-support-for-weibo-and-dribbble-to-greyshade.html
  • http://xautjzd.github.io/blog/2013/07/18/add-navigator/
  • http://xautjzd.github.io/blog/2013/07/18/congfig-disqus-plugin/
  • http://gilguan.github.io/blog/2013/10/16/zai-macshang-shi-yong-octopressda-jian-githubbo-ke/

参考:http://segmentfault.com/blog/yaashion_xiang/1190000000364677


0 0
原创粉丝点击