blog with github(4)-开始写吧,骚年

Octopress提供很多的Rake任务去创建post和pages,他还会根据你的posts来生成Category,你可以在atom.xml或者blog/categories/<category>/atom.xml中找到这些内容

####Post

这些Post页面必须存放在Source/_posts目录下面,并且命名方式和jekyll的命名方式一样,会转换成YYYY-MM-DD-Post-title.markdown,这个文件的名字就是你的blog的url slug,日期帮助你排序这些文章

1
rake new_post["Title"]

在使用了ZSH的话,你要这样创建

1
rake new_post或者rake new_post[\"Title\"]

例如

1
2
rake new_post["Zombie Ninjas Attack: A survivor's retrospective"]
Creates source/_posts/2011-07-03-zombie-ninjas-attack-a-survivors-retrospective.markdown

or

1
2
3
4
~/Code/rails/octopress(branch:source) » rake new_post                        
Enter a title for your post: blog-with-github-4
mkdir -p source/_posts
Creating new post: source/_posts/2013-06-03-blog-with-github-4.markdown

生成的内容大致如下

1
2
3
4
5
6
7
8
---
layout: post
title: "Zombie Ninjas Attack: A survivor's retrospective"
date: 2011-07-03 5:59
comments: true
external-url:
categories:
---

你可以关闭comments,或者为他添加categories的tag,并且你还可以添加author: Your Namepublished: false来控制是否发布

####Page

生成Page的命令

1
2
3
4
rake new_page[super-awesome]
# creates /source/super-awesome/index.markdown

rake new_page[super-awesome/page.html]

如果使用了zsh的话,方法要参照post的创建方式

生成的pages的默认内如大致如下

1
2
3
4
5
6
7
8
---
layout: page
title: "Super Awesome"
date: 2011-07-03 5:59
comments: true
sharing: true
footer: true
---

####Content

如果列表中不想显示全文内容的话,可以添加<!-- more -->标签,这将在文章下面生成一个“Continue →” 链接,链接到全文的地址

###Generate & Preview

1
2
3
rake generate   # Generates posts and pages into the public directory
rake watch # Watches source/ and sass/ for changes and regenerates
rake preview # Watches, and mounts a webserver at http://localhost:4000

本地使用http://localhost:4000就可以访问了

blog with github(3)-Octopress配置

Octopress的配置相当的简单,并且一般配置完成后,你不需要再对Rakefile和_config文件进行修改,下面这些是Octopress的配置文件

1
2
3
4
5
_config.yml       # Main config (Jekyll's settings)
Rakefile # Configs for deployment
config.rb # Compass config
config.ru # Rack config

Rakefile大多是与部署相关的配置,如果不需要同步的话,你就不需要进行修改

####Blog配置

_config.yml有三部分配置,你必须修改url,并且title,subtitle和author也要修改,还有一些第三方的服务需要启用

#####主配置

1
2
3
4
5
6
7
8
9
10
11
url:                # For rewriting urls for RSS, etc
title: # Used in the header and title tags
subtitle: # A description used in the header
author: # Your name, for RSS, Copyright, Metadata
simple_search: # Search engine for simple site search
description: # A default meta description for your site
date_format: # Format dates using Ruby's date strftime syntax
subscribe_rss: # Url for your blog's feed, defauts to /atom.xml
subscribe_email: # Url to subscribe by email (service required)
category_feeds: # Enable per category RSS feeds (defaults to false in 2.1)
email: # Email address for the RSS feed if you want it.

#####Jekyll&Plugins

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root:               # Mapping for relative urls (default: /)
permalink: # Permalink structure for blog posts
source: # Directory for site source files
destination: # Directory for generated site files
plugins: # Directory for Jekyll plugins
code_dir: # Directory for code snippets (for include_code plugin)
category_dir: # Directory for generated blog category pages

pygments: # Toggle python pygments syntax highlighting
paginate: # Posts per page on the blog index
pagination_dir: # Directory base for pagination URLs eg. /blog/page/2/
recent_posts: # Number of recent posts to appear in the sidebar

default_asides: # Configure what shows up in the sidebar and in what order
blog_index_asides: # Optional sidebar config for blog index page
post_asides: # Optional sidebar config for post layout
page_asides: # Optional sidebar config for page layout

#####第三方配置

1
2
3
4
5
6
7
8
9
Github - List your github repositories in the sidebar
Twitter - Setup a sidebar twitter feed, follow button, and tweet button (for sharing posts and pages).
Google Plus One - Setup sharing for posts and pages on Google’s plus one network.
Pinboard - Share your recent Pinboard bookmarks in the sidebar.
Delicious - Share your recent Delicious bookmarks in the sidebar.
Disqus Comments - Add your disqus short name to enable disqus comments on your site.
Google Analytics - Add your tracking id to enable Google Analytics tracking for your site.
Facebook - Add a Facebook like button

blog with github(2)-部署到github

###使用github pages

如果想使用 http://username.github.io 的域名作为你的blog地址的话,首先要创建一个仓库,名字为你的用户id.github.io(比如我的是welsonla.github.io)

用户使用的是Github Pages的master版本下面的public作为你的网站主目录,你可以通过浏览http://username.github.io 来查看。如果你想在source这个版本上面维护代码,并且把内容提交到master分支,Octopress有一个命令来帮助你完成这些

1
rake setup_github_pages

然后,他将

  1. 询问你的github pages的url
  2. 将远程的重‘origin’重命名为‘octopress’
  3. 在远程的origin讲你的github pages仓库添加进去
  4. 切换当前branch从master切换到source
  5. 根据你的仓库名,重新配置你的blog地址
  6. 在_deploy目录下面设置master分支,用于部署

接下来执行

1
2
3
rake generate
rake deploy

这将生成你的blog,并将生成的文件copy到_deploy目录下面,并添加到git,将他们commit和push到master分支上面,稍后,你会收到一份来自github的email告诉你,你的提交已经收到,并且很快将发不到你的web上面

并且,不要忘记提交你的代码到source分支

1
2
3
git add .
git commit -m 'your message'
git push origin source

####自定义域名绑定

首先你要source目录下面创建一个CNAME,

1
echo 'your-domain.com' >> source/CNAME

之后去你的域名服务商或者你的dns服务商那里创建一条CNAME记录,记录指向的IP为
(不要使用顶级域名指向到pages,要使用二级域名)

1
207.97.227.245

blog with github(1)-前期准备

##开始之前

  1. 安装Git
  2. 使用rbenv或者RVM安装ruby 1.9.3

安装完后确保你的ruby版本是1.9.3

1
ruby -v

##设置Octopress

1
2
git clone git://github.com/imathis/octopress.git octopress
cd octopress

接下来安装一些依赖

1
2
3
gem install bundler
rbenv rehash
bundle install

安装Octopress默认主题

1
rake install

–未完待续,哥去睡觉

different of class and category

当需要重写父类中的方法时,这时候定义子类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
@interface JADanSideController : JASidePanelController


@end


@implementation JADanSideController

- (UIBarButtonItem *)leftButtonForCenterPanel{

UIButton *leftBarButton = [UIButton buttonWithType:UIButtonTypeCustom];
[leftBarButton setFrame:CGRectMake(0, 0, 44, 30)];
[leftBarButton setBackgroundImage:[UIImage imageNamed:@"List_NaviSide.png"] forState:UIControlStateNormal];
[leftBarButton addTarget:self action:@selector(toggleLeftPanel:) forControlEvents:UIControlEventTouchUpInside];
__autoreleasing UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBarButton];

return leftBarButtonItem;
}

@end

当需要为父类添加方法时,这时候定义类别

1
2
3
4
5
6
@interface JADanSideController : JASidePanelController

- (void)setBackGroundColor;

@end

生成 github SSH keys

本文主要来自github官方,Generating SSH Keys

1
2
3
4
5

cd ~/.ssh

ssh-keygen -t rsa -C "your_email@example.com"

下面的步骤可以只敲回车进行确认即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Creates a new ssh key using the provided email

Generating public/private rsa key pair.

#这里直接回车就会生成一个默认名为id_rsa
Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]


#这里需要你输入一个你加密的key(一定要记住)
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]


Your identification has been saved in /Users/welsonla/.ssh/id_rsa.
Your public key has been saved in /Users/welsonla/.ssh/id_rsa.pub.
The key fingerprint is:
30:e8:aa:08:ee:bc:76:88:2c:3f:83:39:b0:6e:95:cc wyc.jar@gmail.com
The key's randomart image is:
+--[ RSA 2048]----+
| |
| . |
| . o |
| . o |
| o o S |
|. E |
|=++ |
|%*o. |
|OO+o |
+-----------------+

看到这个界面说明生成成功

copy加密字符到剪切板

1
pbcopy < ~/.ssh/id_rsa.pub

打开你的github

1
2
3
4
5
6
7
1. 点击 Account Settings
2. 点击左侧 "SSH Keys"
3. 点击 "Add SSH key"
4. 粘贴你的可以到 "Key" 输入框
5. 点击 "Add key"
6. 输入你的github密码确认

使用RVM安装ruby

今天突然发现ruby版本不小心又回到了1.8.7,可能是我修改了rvm的配置文件导致的,于是开始折腾安装rvm和ruby

首先还是先安装Homebrew吧
很简单,一行代码搞定

1
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

安装RVM

1
curl -L https://get.rvm.io | bash -s stable --ruby

走着走着发现出错了

1
2
3
4
5
6
Missing required packages: autoconf, automake, libtool, pkg-config, libyaml, readline, libxml2, libxslt, libksba, openssl, sqlite.
RVM autolibs is now configured with mode '2' => 'check and stop if missing',
please run `rvm autolibs enable` to let RVM do it's job or run and read `rvm autolibs [help]`
or visit https://rvm.io/rvm/autolibs for more information.
There were package installation errors, make sure to read the log.
Check Homebrew requirements https://github.com/mxcl/homebrew/wiki/Installation

透过错误信息,发现缺少一写依赖的包,和rvm的autolibs没打开,这时候我们就通过Homebrew先安装上(具体你要看清楚你缺少的是什么)

1
2
3
rvm autolibs enable
rvm reload
brew install autoconf automake libtool pkg-config libyaml readline libxml2 libxslt libksba openssl sqlite

漫长的等带后,依赖包终于装完了
再次安装RVM

1
curl -L https://get.rvm.io | bash -s stable --ruby

就会安装成功,你可以rvm -v查看下版本

安装并设置1.9.3为你的默认版本

1
2
3
rvm install 1.9.3
rvm use 1.9.3
rvm rubygems latest

Finish