WenJunjie Blog

sysadmin

Octopress-github

| Comments

介绍

octopress

系统环境

OS X 10.8.2

1. 安装Homebrew

ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
brew update 

2. 安装Xcode Command Line Tools或OSX GCC Installer及brew install git

Ruby

1. 安装RVM

bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

2. 安装ruby1.9.3(Octopress >1.9.2)

rvm install 1.9.3 && rvm use 1.9.3

3. 安装Pow

curl get.pow.cx | sh
cd ~/.pow
ln -s ~/Documents/jackwen.github.com octopress
rake watch
open http://octopress.dev

Octopress

1. 下载Octopress

git clone git://github.com/imathis/octopress.git jackwen.github.com
cd jackwen.github.com << yes
ruby --version

2. 安装插件

gem install bundler
bundle install

3. 安装主题

rake install

发布

1. 创建github repo

创建yourname.github.com,yourname必须与你github账户名称相同 git://github.com/yourname/yourname.github.com

2. 配置本地与github网址关联

rake setup_github_pages 

url输入:git://github.com/yourname/yourname.github.com

3. 修改博客配置

vim _config.xml

4. 写文章

rake new_post['title']

如果shell是zsh,可能会出现:

> zsh: no matches found: new_post[xxx]

修改.zshrc,加上这行:

alias rake="noglob rake"

或改rake命令 rake “new_post[title]”

5. 生成

rake generate

6. 预览

rake preview
open http://127.0.0.1:4000
or
rake watch
open http://octopress.dev

7. 部署

rake deploy

8. 备份

git add .
git commit -m 'your message'

增加独立域名

一级域名example.com A 204.232.175.78 二级域名blog.example.com CNAME yourname.github.com

echo "example.com" > source/CNAME

写作

生成source/_posts yyyy-mm-dd-title.markdown,可使用Markdown编辑器Mou、iA Wirter、Byword打开编辑

rake new_post["title"]
# creates source/_posts/title.markdown

rake new_page[service]
# create source/service/index.markdown
rake new_page[service/page.html]
# creates source/service/page.html

添加侧边栏

添加豆瓣 vim source/_includes/custom/asides/douban.html

<section>
<h2>Douban List</h2>
<div>
    <script type="text/javascript" src="http://www.douban.com/service/badge/livestrong/?show=dolist&amp;n=6&amp;columns=3&amp;hidelogo=yes&amp;hideself=yes" ></script>     </div>
</section>

获取豆瓣js vim _config.yml

# Douban
douban_user: yourusername

在default_asides添加: custom/asides/douban.html

SEO

提交sitemap.xml https://www.google.com/webmasters/tools/

设置meta data:增加keyywords和description

为主页设置keywords和description vim _config.yml

url: http://junjiewen.com
title: WenJunjie Blog
subtitle: sysadmin
author: WenJunjie
simple_search: http://google.com/search
description: sysadmin ops
keywords: sysadmin linux

为每页增加keywords和descripion

vim source/_includes/head.html

<meta name="author" content="WenJunjie">

<meta name="description" content="sysadmin ops">
<meta name="keywords" content="sysadmin linux">

vim Rakefile

task: new_post
...
  open(filename, 'w') do |post|
    post.puts "---"
    post.puts "layout: post"
    post.puts "title: \"#{title.gsub(/&/,'&amp;')}\""
    post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
    post.puts "comments: true"
    post.puts "categories: "
    post.puts "keywords: "
    post.puts "description: "
    post.puts "---"
  end

跳转到单个域名Redirect to single domain

vi Gemfile

gem 'rack-rewrite'

vi config.ru

require 'bundler/setup'
require 'sinatra/base'
require 'rack-rewrite'

# The project root directory
$root = ::File.dirname(__FILE__)

ENV['RACK_ENV'] ||= 'junjiewen.com'
ENV['SITE_URL'] ||= 'www.junjiewen.com'
use Rack::Rewrite do
    r301 %r{.*}, "http://#{ENV['SITE_URL']}$&", :if => Proc.new {|rack_env|
        ENV['RACK_ENV'] == 'production' && rack_env['SERVER_NAME'] != ENV['SITE_URL']
    }
    r301 %r{^(.+)/$}, '$1'
end

bundle install bundel show |grep rake-rewrite

Comments