怎么在github 搭建 Octopress

git 和 github 配置

1.先注册一个github账号, 创建github pages 。

创建一个新的Repository。这里须要重视的是,若是想要博客的首页是http://yourname.github.com,则Repository的project name就必须是yourname.github.com。

安装Git并进行设置,mac下git默认已经装好 。

2.接下来设置 SH Keys .

履行ssh-keygen -t rsa -C “your_email@youremail.com”,回车。

然后输入两遍暗码。

到c:\Users\用户名.ssh\目次找到id_rsa.pub,并用文本软件打开复制全部。目录是隐藏的。

3.将SSH Key添加到GitHub

到github网站选择“Account Settings”>>“SSH Public Keys”>>“Add another public key”,将刚才复制的内容粘贴到key文本框内。

4. 测试

为确保设置成功,现在可以测试设置成果啦。记住,”[email protected]”是默认的,无需修改。

    $ ssh -T [email protected]  (也可以用 SSH -v [email protected]
5.设置个人信息

现在,你已经成功安装Git,并设置好SSH Keys,是设置个人信息的时候啦:

设置用户名和电子邮件 $ git config –global user.name “Firstname Lastname” $ git config –global user.email “[email protected]

安装ruby 1.9.3 版本 ,因为目前2.0 Octopress 需要的真是 1.9.3 ,否则到后边rake install 不会有问题的。

mac 本身的版本比这个低。 id:http://www.moncefbelyamani.com/how-to-install-xcode-homebrew-git-rvm-ruby-on-mac/ “安装可以参看这篇文章。”

Octopress安装和配置

1.安装Octopress

建立一个放置Octopress的目录,这里是oblog文件夹,clone octopress程序到本地,替换username为你的自定义名称

    cd ~/oblog/
    git clone git://github.com/imathis/octopress.git username.github.com
    cd ~/oblog/username.github.com
    gem install bundler
    bundle install

接下来 rake setup_github_pages //配置github项目地址 接下来会提示输入url Enter the read/write url for your repository
(For example, ‘[email protected]:your_username/your_username.github.com)

    rake install    //是安装Octopress默认主题的
    rake new_post["Hello World"]   //建立新文章,文章存放在source/_post里面,格式为md的,现在就找个爽快点的[编辑器](#editor)来写文章了

    rake generate  //生成静态文件
    rake preview  //开启站点预览,动态生成, http://127.0.0.1:4000
    rake deploy  //生成静态并部署到github
    选择性的备份source文件夹到github,这样就有了文章md源文件的版本管理

提交的代码到git库 git add . git commit -m “your message log 例:保存source文件夹,文章源文件” git push origin source //建立sourch分支并保存

以后写文章就只需要用 rake generate rake deploy

2.Ocotpress博客配置

更改下面的配置后,还需要运行 rake generate、rake deploy等等命令的。

1、默认的博客运行成功的话,就需要按照自己的要求对博客配置进行修改了,主要是修改Octopress根目录下的主配置文件_config.yml。

    url:  http://username.github.com                      博客地址
    title:  username's blog                               博客标题
    subtitle: A blogging framework for hackers.           副标题
    author:  xhhjin                                       作者
    simple_search:  http://www.google.com.hk/search       搜索引擎
    description:                                          关于博客的描述
    subscribe_rss:  /atom.xml                             Rss订阅地址, 默认是  /atom.xml
    subscribe_email:                                      提供Email订阅的地址
    email:                                                Rss订阅的Email地址
    root:/                                                博客路径,默认是"/",如果你打算在子目录中,记得修改这个路径
    permalink: /blog/:year/:month/:day/:title/            文章的固定链接形式

2.Jekyll & Plugins

    paginate: 10                    # 每页的文章数量,超过翻页
    recent_posts: 5                 # 右侧“最近发表”的模块里显示的文章数量
    excerpt_link: "Read on &rarr;"  # 在文章中使用<!-- more -->,列表页将不再显示全文,而是显示“Read on”的链接,指向全文
    default_asides: [asides/recent_posts.html, asides/github.html, asides/twitter.html]    # 用于配置侧边栏

呵呵,我的第一篇博文算是写完了,希望和大家多交流,互相学习。

我安装过程中碰到的问题。

操作如果没有响应 ,有的是需要翻墙的 . 而且需要sudo权限 . 使用bundle 之前需要安装 gem install liquid 如果出错看提示,根据提示跟新 我在装 liquid 的时候就需要更新这个 gem update –system 之后在安装 liquid . 之后就可以使用 bundle 了 . 留意bundle update 提示使用的 rake 和 安装 rake 版本是否一致。不然会出错。(卸载不一样的版本 gem uninstall rake -v=10.0.3)

或者 在终端提示You have already activated rake 10.0.2, but your Gemfile requires rake 0.9.2.2. Using bundle exec may solve this.,解决办法,找到Gemfile文件,修改gem rake对应那行为10.0.2即可。 我用的以上的方法。

Fetching gem metadata from http://rubygems.org/........ Fetching gem metadata from http://rubygems.org/.. Installing rake (0.9.6)

使用rake 命令遇到问题: C:\ruby186\workspace>rake db:migrate rake aborted! No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb) c:/ruby186/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2377:in `raw_load_rakef ile’ (See full trace by running task with –trace) 原因:没有进入工程目录。

github page博客搭建参考在github上用octopress搭建博客,关于ruby的安装可参考Ruby在windows下的安装 。下面是自己安装过程中碰到的几个错误,分享下:
(1) ruby安装目录不能包含空格,否则在某些gem install会报错
(2) rake setup_github_pages 提示:window No such file or directory – git remote -v 这是因为windows 的cmd没有配置git路径,只要在环境变量path中加入git的bin目录即可
(3) invalid byte sequence in GBK rake setup_github_pages 这是因为本机windows的cmd默认为gbk,运行命令set LC_ALL=en_US.UTF-8 set LANG=en_US.UTF-8先
(4) rake deploy 提示## Deploying website via Rsync FAILED rake deploy 没有先rake setup_github_pages