热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

用Octopress在github上写博客

2019独角兽企业重金招聘Python工程师标准1.安装git及依赖yum-yinstallgityum-yinstallgcc-cpatchreadlinereadline

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

1.安装git及依赖
yum -y install git
yum -y install gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel

2.安装rvm
otopress官方要求用ruby 1.9.3,ruby可以通过rbenv或者RVM(Ruby版本管理,Ruby Version Manager)来安装。安装RVM也是有讲究的,分为单用户安装和多用户安装,建议用单用户安装,即直接在用户权限下进行,所以要注意下~/下面的文件夹是否有w权限;若要多用户安装,则在命令前加sudo,不要在root下直接进行安装。
安装前要有编译软件如gcc,如果这一步一直有error的话,不妨先安装gcc。

curl -L https://get.rvm.io | bash -s stable –ruby
#如果curl报错的话就先install curl
然后在~/.bashrc文件后面添加下列语句:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source ”$HOME/.rvm/scripts/rvm”
# RVM bash completion
[[ -r "$HOME/.rvm/scripts/completion" ]] && source ”$HOME/.rvm/scripts/completion”
之后在当前shell中载入rvm环境:
source ~/.bashrc
也可以重新打开一个shell,就自动载入了

检查:
type rvm | head -n1
#若返回$ rvm is a function则说明安装成功,否则检查一下前面步骤有没有报错,权限、载入与否等
rvm notes
#检查rvm函数是否工作
rvm requiments
#查看其他依赖并从源中安装,这时终端中会出现下列信息
Additional Dependencies:

# For Ruby / Ruby HEAD (MRI, Rubinius, & REE), install the following:

ruby: yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel

## NOTE: For centos >= 5.4 iconv-devel is provided by glibc

注释:将yum那一段复制,在另一个终端中执行即可安装。不同电脑所需要的依赖也不同。
Ruby中文社区的wiki文档里面有一句单独安装readline的命令,这里已经包括了

3.安装Ruby环境

rvm list known
rvm install 1.9.3
rvm use 1.9.3 –default(设置默认)
rvm list
#查看安装的rubies
rvm [-v] [--version]
#查看版本
rvm remove 
#卸载一个版本

4.设置Octopress

结构:

1 .rvmrc
改成使用我机子上装的Ruby版本(1.9.3),Octopress最低要求是1.9.2。
2 Gemfile
把源改成ruby.taobao.org,去掉部分gem的版本号限制,咱都用最新的。
3 Rakefile
用haml替换markdown(这个根据自己喜好来,只要是被支持的),时间改成东八区的,降低主题对custom目录的依赖。
4 _config.yml
这里都是一些定制化的配置信息,比如日期格式、永久链接、新浪微博等。
5 plugins/sh_js.rb
[新增] 代码高亮插件,具体介绍看:Using SHJS for Jekyll
6 plugins/tag_generator.rb
[新增] 其实Jekyll是支持Tag的,只不过Octopress目前没有官方插件支持,所以我自己搞了个,支持中文。
7 .themes/blog/

到准备好的目录下,先把Octopress从仓库里clone下来

git clone git://github.com/imathis/octopress.git octopress
cd octopress
#如果使用的是RVM,这一步会被讯网你是否相信.rvmrc,选择yes
gem install bundler
bundle install
#安装依赖
rake install['Theme Name']
#安装主题,无参数则是默认主题
【参考:http://www.360doc.com/content/12/0421/21/1016783_205514919.shtml】

通过octopress/_config.yml修改博客设置,诸如博客标题,插件,以及url格式等,这个很重要,稍后会说。

然后登录GitHub并注册一个帐号,创建一个repository,这里有两种方式:

1.GitHub的用户/组织页面(Github User/Organization pages)。这样的话repository需命名为user.github.com,这样的页面只能有一个。可通过http://username.github.com来访问。
2.GitHub的项目页面(Github projects pages)。repository可任意命名,这样的页面可拥有多个。通过http://username.github.com/repo_name来访问,Github会寻找项目中gh-pages分支,并且在浏览器中显示出其中的网页内容。所以我选择了第二种

下面采用第一种方式:

github创建geekwolf.github.io库(暂不要自动生成网页)

cd octopress
rake setup_github_pages
输入geekwolf.github.iossh链接地址:git@github.com:geekwolf/geekwolf.github.io.git

rake generate
#产生静态文件,将文件从source/复制到public/

rake preview
#本地预览,地址栏输入localhost:4000/repo_name

rake deploy
#将文件从public/复制到_deploy/,再从_deploy/中推送到远端仓库(默认远端master分支),需要ssh publickey

下面将octopress源文件传送到远端source分支

git remote add origin git@github.com:geekwolf/geekwolf.github.io.git
#repository设置为默认的远端仓库
git config branch.master.remote origin
#master分支和origin远端仓库对应
git branch -m master source
#rename branch
git add .
git commit -m ’blog source’
git push origin source

以上完成后,每次博客更改过通过rake generate 生成静态页面,然后通过rake deploy发布到远端master分支,从而发布网站

  5.绑定域名

echo “linuxhonker.com”>> oectopress/source/CNAME
修改A记录为207.97.227.245

6.新机器使用方法

克隆远端source分支到本地octopress目录
git clone -b source git@github.com:geekwolf.github.io.git octopress
克隆远端master分支到octopress下的_deploy目录
cd  octopress
git clone -b git@github.com:geekwolf.github.io.git _deploy

然后继续
gem install bundler
bundle install
rake setup_github_pages
rake generate
git add .
git commit -am “some comment here”
git push origin source (update the remote source branch)
rake deploy(update the remote master branch)

参考:
Windows下部署方式:
http://www.freehao123.com/octopress/
Octopress定制:
http://biaobiaoqi.me/blog/2013/07/10/decorate-octopress/
http://octopress.org/docs/blogging/
http://octopress.org/docs/configuring/
其他参考:
http://blog.zerosharp.com/clone-your-octopress-to-blog-from-two-places/
http://www.psichen.com/octopress-static-blog
Git提交本地分支到远程分支操作
http://www.cnblogs.com/springbarley/archive/2012/11/03/2752984.html
Vim markdown插件
http://whbzju.github.io/blog/2013/02/02/octopress-peizhi/


转:https://my.oschina.net/geekwolf/blog/184173



推荐阅读
author-avatar
手机用户2502927277
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有