IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    在多台电脑上写Octopress博客

    Dreams Come Ture发表于 2014-10-12 02:49:23
    love 0
    我将介绍如何在多台电脑上部署Octopress,我假设你已经会在一台电脑上部署Octopress了,如果你还不会或者甚至不知道Octopress是什么,那么就先看看Octopress的[官网](http://www.octopress.org),然后跟着Document一步一步安装部署就行了。也许你弄坏了本地的Octopress文件,重装了电脑,或和我一样有了一台新电脑:),下面的内容都会告诉你怎么做。

    Octopress原理

    我以部署到Github为例,Octopress的git仓库(repository)有两个分支,一个叫master,这个是默认的,不能改,被存储在blog根目录的_deploy文件夹下,是用来存放生成好的blog站点文件的。另一个叫source(名字可以自己定义,此文中指定为source),是用来存放markdown源文件,theme,plugin等用于生成blog所需要的所有文件的。

    git branch source   //创建本地source分支  
    git checkout source //切换本地分支到source  
    git add --all           //将所有文件add到source分支  
    git commit -m "init"    //commit  
    git push origin source  //将source分支push到服务器  
    

    创建一个本地的Octopress仓库

    重新创建一个已经存在的本地Octopress仓库只需要以下几个简单的步骤即可。

    克隆(clone)博客到新机器

    首先将博客的源文件clone到本地的octopress文件夹内。

    $ git clone -b source git@github.com:username/username.github.com.git octopress
    

    然后将博客文件clone到octopress的_deploy文件夹内。

    $ cd octopress
    $ git clone git@github.com:username/username.github.com.git _deploy
    

    然后安装博客,即bundler和需要的rubygem。

    $ gem install bundler
    $ rbenv rehash    # If you use rbenv, rehash to be able to run the bundle command
    $ bundle install
    $ rake setup_github_pages  # I am not run this command.
    

    如果你设置了自定义域名,需要将根目录的_config.yml里的url再改成你自己的域名。 这样就建好了一个新的本地仓库了。

    更新和推送

    当你要在一台电脑写博客或做更改时,首先更新source仓库。更新master并不是必须的,因为你更改源文件之后还是需要rake generate的。

    $ cd octopress
    $ git pull origin source  # update the local source branch
    $ cd ./_deploy
    $ git pull origin master  # update the local master branch
    

    写完博客之后不要忘了推送到remote,下面的步骤在每次更改之后都必须做一遍。

    $ rake generate
    $ git add .
    $ git commit -am "Some comment here." 
    $ git push origin source  # update the remote source branch 
    $ rake deploy             # update the remote master branch
    

    总结起来就是:

    1. 从远端source和master同步数据
    2. 写文章(或其他改动,例如更改theme)
    3. push到远端source分支
    4. rake deploy(相当于push到远端master分支)


沪ICP备19023445号-2号
友情链接