Github Pages中的Octopress框架搭建个人博客 (上)

转自:https://www.cnblogs.com/wanxudong/p/6772684.html

Github Pages中的Octopress框架搭建个人博客

一、预备知识:

1、shell command

2、Git

二、搭建过程:

下面是具体的安装步骤(这里使用RVM安装,还可以通过rbenv安装,Octopress给出的官方安装文档:Octopress Setup):

一、查看ruby版本

1
ruby --version  # 根据Octopress官方文档Ruby必须 >= 1.9.3-p0

如果ruby版本 >= 1.9.3-p0 ,跳过RVM和Ruby的安装。

二、安装RVM

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

 

三、安装Ruby 1.9.3

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

 

 

四、安装 Octopress

1、将 Octopress的项目clone到本地:

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

2、更新ruby源,将官方的ruby源替换成国内淘宝的源。

1
2
3
gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/ gem sources -l

3、安装依赖:

1
2
gem install bundler # 若遇权限问题加上sudo重新执行,并输入密码。
bundle install

4、最后安装 Octopress

1
rake install       # 安装octopress默认主题

 

 5、修改Octopress初始配置

1
2
ls                 # 查看当前目录所有文件
vim _config.yml    # 通过vim编辑主要配置

image

注:可以看到如下代码:

1
2
3
4
5
6 7 8 9 10 11 12 13 14 15 
# ----------------------- #
# Main Configs # # ----------------------- # #网站地址,这里是GitHub项目地址,为必填 url: http://userName.github.io #网站标题 title: user的博客 #网站副标题 subtitle: 天行健,君子以自强不息。 #网址作者 author: userName #搜索引擎 simple_search: https://www.google.com/search #网站的描述,出现在HTML页面中的 meta 中的 description description:

确保在octopress目录,执行命令

1
2
rake generate  # 生成静态站点
rake preview   # 预览静态站点,在http://localhost:4000

六、部署到GitHub Pages上

  在 GitHub 上创建一个New repository,Repository name即项目名称命名规则为 userName.github.iouserName必须与用户名称一致。Tips:最好不要勾选README,免得同步到远程仓库的时候需要做额外的pull操作。

1、将本地代码仓库同步到GitHub.

1
rake setup_github_pages

2、绑定远程仓库

1
git@github.com:your_username/your_username.github.io.git  # 或者https://github.com/your_username/your_username.github.io

3、创建一篇文章

1
rake new_post["title"]

4、生成新的文章在source/_posts/目录下

1
2
cd source/_posts   # 命令行cd到posts目录下
open ./ # 打开目录文件夹

   这个时候会在目录里看到.markdown后缀的文件,我们可以通过一些第三方的Markdown编辑器打开。在这里我使用的是Mou(下载地址:这里),Mou附带实时预览,文档说明里也将markdown语法说的很详细,这里不再赘述。

5、编辑完成后生成静态站点,终端执行命令:

1
rake generate     # 此命令需在octopress根目录执行,若当前目录为source/_posts,执行两次cd ..返回到根目录再执行此命令。

6、预览本地的站点,执行指令:

1
rake preview

7、在浏览器打开localhost:4000 查看网页效果效果。如果没有问题可以将静态站点同步到 GitHub远程仓库中。执行命令

1
rake deploy      #同步到GitHub服务器

  打开GitHub稍等一会儿,就会看到我们的静态网页已经被同步到GitHub仓库的master分支上了。浏览器访问访问username.github.io,就会发现个人博客已经创建成功。

最后,创建source分支。Octopress的Git仓库(repository)有两个分支,分别是mastersource

  • source分支存储的是生成博客的源文件,在octopress根目录下。
  • master分支存储的是博客网站本身master的内容,在根目录的_deploy文件夹内,当你push源文件时会忽略,它使用的是rake deploy命令来更新的。
1
2
3
4
git checkout source
git add .
git commit -m "comment" #"comment"为提交的log日志 git push origin source

8、git操作代码如下:

1
2
3
4
5
6 
git remote -v               # 显示所有远程仓库
git pull origin source      # 取回远程仓库的变化 git branch # 列出所有本地分支 git checkout [branch-name] # 切换到指定分支,并更新工作区 git merge [branch] # 合并指定分支到当前分支 git log # 查看当前分支的版本历史

猜你喜欢

转载自www.cnblogs.com/yinminbo/p/11809693.html