分享 让 Octopress 跟 GitLab 合作发布博文

zenz · 2013年08月07日 · 最后由 zenz 回复于 2013年08月07日 · 3397 次阅读

继续分享

基本上网上的文章在介绍 Octopress 时,都是引用官方的配置法,发布到 github,heroku 或者是用 rsync。但这些都不是我想要的。因为我有一台 GitLab 服务器,因此 Octopress 跟 GitLab 服务器配合才是我最理想的解决方案。

所以,就行动吧(我的 GitLab 服务器是架设在 CentOS6.4 上面的 GitLab5.4,用 Nginx 作为 Proxy,见另一篇博文)。

第一步,在 GitLab 上建立一个项目,例如 simon_blog,然后登录上 GitLab 所在的服务器,进行以下操作 (git 用户):

cd /home/git/repositories/simon_blog.git touch hooks/post-receive cat << EOF hooks/post-receive >#!/bin/sh >GIT_WORK_TREE=/home/git/gitlab-blog git checkout -f master >EOF chmod +x hooks/post-receive mkdir /home/git/gitlab-blog git init . git remote add simon_blog /home/git/repositories/simon_blog

第二部,在用于写作的个人电脑上(已经装好 RVM 的 Ruby 环境等),进行下述操作:

git clone git://github.com/imathis/octopress.git octopress cd octopress bundle install --path vendor/bundle

修改基础的配置_config.yml 文件。然后就是最关键的部分了。

git remote rename origin octopress git remote add origin [email protected]:simon_blog git config branch.master.remote origin git branch -m master source rm -rf _deploy mkdir _deploy cd _deploy git init . echo "nothing here yet" > index.html git add index.html git commit -m "Init…" git remote add origin [email protected]:simon_blog git push origin master

剩下的事情就是修改 Rakefile,让它能正确通过 git 发布。

deploy_default = "push" deploy_branch = "master"

建立一篇新的博文:

bundle exec rake new_post["博文标题"]

在 source/_posts/目录里面用 Mou 慢慢写呗。写完了发布:

bundle exec rake generate bundle exec rake deploy

因为 post-receive 的 hooks 起作用,Octopress 生成的网站会被自动同步到/home/git/gitlab-blog 目录。那么 Nginx 的配置就不要说了吧。

当然,这个配置有个缺点,就是要求博客跟 GitLab 服务在同一台服务器上。但这不是我需要关心的。

你搞的好复杂哦。Octopress 本身是很简单的,直接本地生成静态文件,至于你想发到什么服务器上都随便你,又没有数据库,评论也可以配置第三方的 disqus。所以你随便找个静态空间,那种一年 100 块钱的那种,然后你修改哈配置,使用 LFTP 传输文件,这样就可以自动生成,自动发布你的 BLOG 了。

#1 楼 @outman 说的对!但是我是无聊人,热爱折腾。呵呵。

#3 楼 @outman 另外,跟 GitLab 配合还有一个好处,就是可以随时看版本。

#4 楼 @zenz 你把 blog 源代码放到 bitbucket.org 也可以嘛。也比较方便,还是私有的。

#5 楼 @outman 大哥,我自己有服务器还放到别人那?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号