Mic

Memories are too important

Octopress: Setting Up a Blog and Contributing to an Existing One

Origin post here: http://code.dblock.org/octopress-setting-up-a-blog-and-contributing-to-an-existing-one

Octopress documention can be quite confusing. It took me a while to understand what the heck Octopress is doing to branches and remote origins. It actually pretty simple, so I am going to try to un-confuse you. I will also show you a better way to contribute to an existing blog and explain what’s happening in those Rake tasks.

Octopress文档可能很让人费解。我花了好久才弄明白Octopress究竟对branches与remote origins做了啥。实际上非常简单,所以我尽量解除你的疑惑。我会给你展示一个更好的方法来写一个已经存在的博客,并解释那些rake命令运行时发生了什么。

We are going to deploy a blog to Github pages, so we need a project, such as ‘username.github.com’. Go to Github to create one. Use your username instead of “username”.

我们将在Github pages上部署一个博客,故我们需要一个像’username.github.com’的项目。去Github新建一个。此处使用你的Github用户名替换’username’。

Next, fetch Octopress and install it locally. This gets the files from its main repository and applies a default theme.

然后,fetch Octopress并装在本地环境。从主仓库就拿到文件并应用默认主题:

本地安装Octopress
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ git clone git://github.com/imathis/octopress.git octopress

Cloning into octopress...
remote: Counting objects: 6046, done.
remote: Compressing objects: 100% (2420/2420), done.
remote: Total 6046 (delta 3448), reused 5549 (delta 3097)
Receiving objects: 100% (6046/6046), 1.26 MiB | 426 KiB/s, done.
Resolving deltas: 100% (3448/3448), done.

$ cd octopress
Using /home/dblock/.rvm/gems/ruby-1.9.2-p290

octopress$ bundle install
Fetching source index for http://rubygems.org/
...
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

octopress$ rake install
## Copying classic theme into ./source and ./sass

Octopress comes with some handy Rake task to get you started. To deploy to Github pages run rake setup_github_pages. When prompted, enter the GIT URL to your new repository, suck as git@github.com:username/username.github.com.git

Octopress自带称手的Rake任务工具让你启动。运行命令rake setup_github_pages来部署到Github pages。出现输入提示时,输入GIT URL到新仓库,比如git@github.com:username/username.github.com.git

本地配置
1
2
3
4
5
6
7
8
9
10
11
12
13
octopress$ rake setup_github_pages
Enter the read/write url for your repository: git@github.com:username/username.github.com.git

Added remote git@github.com:username/username.github.com.git as origin
Set origin as default remote
Master branch renamed to 'source' for committing your blog source files
Initialized empty Git repository in /home/username/source/octopress/_deploy/.git/
[master (root-commit) 2a4e9e7] Octopress init
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 index.html

---
## Now you can deploy to http://username.github.com with `rake deploy` ##

So what the heck happened here? It pointed our clone to our new repository. It also created a _deploy directory with another git repository that is going to contain everything that is being deployed. The remote in that directory is the same as the one in our octopress directory, but the checked out branch is master. Btw, we’re now on the source branch.

那么这究竟发生了啥事?其把我们的clone指向新的仓库地址。并创建了_deploy目录[?????此处待揣摩]。顺便说一句,我们现在在source branch上。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
octopress$ git remote -v
octopress    git://github.com/imathis/octopress.git (fetch)
octopress    git://github.com/imathis/octopress.git (push)
origin    git@github.com:username/username.github.com.git (fetch)
origin    git@github.com:username/username.github.com.git (push)

octopress$ git branch
* source
 
octopress$ cd _deploy/
octopress/_deploy$ git remote -v
origin    git@github.com:username/username.github.com.git (fetch)
origin    git@github.com:username/username.github.com.git (push)

octopress/_deploy$ git branch
* master

octopress/_deploy$ cd ..

octopress$

Now is a good time to read Blogging Basics. You should edit _config.yml with your blog name, etc. Lets create an article and deploy it.

现在是阅读发博客基础的好时机。你要编辑_config.yml文件的博客名称等配置。我们新建一篇文章并发布:

1
2
octopress$ rake new_post["New Post"]
Creating new post: source/_posts/2012-01-17-new-post.markdown

Edit the generated file and add some text at the bottom. Generate the blog.

编辑所生成文件并在底部增加一些文字。生成博客:

生成博客
1
2
3
4
5
6
7
octopress$ rake generate
## Generating Site with Jekyll
directory source/stylesheets/
   create source/stylesheets/screen.css
Configuration from /home/dblock/source/o/octopress/_config.yml
Building site: source -> public
Successfully generated site: source -> public

You can also preview it with rake preview.Before we deploy the blog, save the source and push it to Github. Note that we’re pushing our source branch.

你也可以用rake preview预览。在部署博客前,保存源文件并推到Github上。注意我们在push我们的source branch:

部署博客到Github
1
2
3
4
5
6
7
8
9
10
11
12
octopress$ git add .

octopress$ git commit -m "Initial blog post."
...

octopress$ git push origin source
Counting objects: 3927, done.
Compressing objects: 100% (1412/1412), done.
Writing objects: 100% (3927/3927), 910.08 KiB, done.
Total 3927 (delta 2257), reused 3848 (delta 2203)
To git@github.com:username/username.github.com.git
* [new branch]      source -> source

You’ll have to repeat the above every time you make changes, to save them.Deploy the blog. What this does it rake everything inside _deploy and push it onto the master branch.

每次你发生改动时,你必须要重复以上操作,来保存他们。部署blog上去。这个rake操作所有东西到_deploy目录并把它推到master分支:

1
2
3
4
5
6
7
8
9
octopress$ rake deploy

## Pushing generated _deploy website
Counting objects: 84, done.
Compressing objects: 100% (74/74), done.
Writing objects: 100% (84/84), 180.40 KiB, done.
Total 84 (delta 2), reused 0 (delta 0)
To git@github.com:username/username.github.com.git
* [new branch]      master -> master

If you go to http://username.github.com you should see your blog with the blog post once Github has regenerated the pages – usually a minute or two. And on https://github.com/username/username.github.com you should be able to see the generated files on master along with a source branch with the blog source.

一旦Github已经生成了页面(这通常要一两分钟),如果你去http://username.github.com你会看到你的博客与文章。并且在https://github.com/username/username.github.com你可看到在master上所生成的文件,和带着blog源码的source分支。

You’ll have to do this every time you want to deploy your changes.So how does one start contributing to an existing Octopress blog (or yourself from a new computer)? What we want is the same setup as above, but not from scratch.

每次部署改变时均需这么干。那么如何在已存在的Octopress blog上(或者你自己从一台新电脑上)续写博客呢?我们想要的与上述设置相同,但不是推倒重来:

续写已存在博客
1
2
3
4
5
6
7
8
9
10
$ git clone git@github.com:username/username.github.com.git
$ cd username.github.com
username.github.com$ git checkout source
username.github.com$ mkdir _deploy
username.github.com$ cd _deploy
username.github.com/_deploy$ git init
username.github.com/_deploy$ git remote add origin git@github.com:username/username.github.com.git
username.github.com/_deploy$ git pull origin master
username.github.com/_deploy$ cd ..
username.github.com$

You’re all set. Create posts and stuff. Happy blogging with Octopress.

一切就绪,新建篇文章,开心使用Octopress博客吧!

Hello World

Memories are too important. Here are helloworld programs for you young, helding splendid dreams!

helloworld.c
1
2
3
4
5
6
7
8
9
/* Hello world program in C */

#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("Hello, World!\n");
    return 0;
}
helloworld.cpp
1
2
3
4
5
6
7
8
9
10
// Hello world program in C++

#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    cout << "Hello World!\n";
    return 0;
}