当前位置: 移动技术网 > IT编程>脚本编程>Ruby > Jekyll静态网站后台引擎使用教程

Jekyll静态网站后台引擎使用教程

2017年12月08日  | 移动技术网IT编程  | 我要评论

以前总想搭建一个自己的个人网站,由于不懂php后台,所以在点点网开过自己的博客,后来慢慢向程序员转变,点点网的博客已经不能满足这个职业特定的需求,于是用worldpress搭建了自己的第一个网站,鼓捣过几天worldpress,从购买域名空间,修改空间域名解析,添加模板,修改模板,了解了worldpress的强大之处,但是鼓捣玩了worldpress之后,没有了写文章的动力,也没有用足够的时间来管理,以至于这个网站夭折。直到现在又开始鼓捣jekyll静态网站后台引擎,下面就讲讲jekyll的学习,以及在用jekyll创建网站的时候遇到的问题。

1.jekyll基于github.com或者bitbucket.org,后者我没有验证,应该也是支持的。不需要数据库,不需要后台知识,用jekyll搭建个人中小型网站就是这么简单。

2.搭建流程(因为我是在windows上安装jekyll,所以会比较麻烦): 

注册一个github.com账号,记住自己的用户名和注册时的邮箱,会在git shell验证时用到。

因为jekyll是基于ruby写的,所以首先安装ruby环境,和ruby包管理工具gem

①ruby安装地址,根据自己的系统选择32和64bit,在链接的页面同时安装development kit

下载安装后需要配置ruby的环境变量,在系统的高级属性里面设置系统的path,之后,可以在控制台检查ruby是否安装成功。输入ruby -v即可。 

ruby dk.rb init//初始化ruby

在ruby安装的config文件里面配置一下ruby的安装目录:

# this configuration file contains the absolute path locations of all
# installed rubies to be enhanced to work with the devkit. this config
# file is generated by the 'ruby dk.rb init' step and may be modified
# before running the 'ruby dk.rb install' step. to include any installed
# rubies that were not automagically discovered, simply add a line below
# the triple hyphens with the absolute path to the ruby root directory.
#
# example:
#
# ---
# - d:/ruby19trunk
# - d:/ruby192dev
#
---
- d:/ruby

②安装development kit工具使用的命令行

 ruby dk.rb install 

③在命令行工具中输入gem install jekyll来安装jekyll。输入jekyll -v检查是否安装成功。如果成功会返回版本号。

④同时,需要安装python环境,下载2版本或者3版本都可以。python安装地址
.之后就可以安装博客所需要的工具了。

  4.1需要安装一个easy_install插件

  4.2安装自己喜欢的高亮工具(highlight),例如pygments、rouge。在你的工程目录的_config.yml里面需要设置:highlighter:rough或者highlighter:pygments,不然会在生成项目是出错。

easy_install pygments

⑤创建一个简单的默认博客命令:

jekyll new blog
 cd blog      //cd是一个常用命令,到达相应的文件夹
 jekyll serve  //使用serve和server是一样的效果

在你的localhost:4000就会有一个默认的博客模板产生。

期间会遇到一些错误:

1.配置文件报错

d:/ruby200-x64/lib/ruby/gems/2.0.0/gems/posix-spawn-0.3.9/lib/posix/spawn.rb:164
: warning: cannot close fd before spawn
'which' is not recognized as an internal or external command,
operable program or batch file.
 liquid exception: undefined method `[]' for nil:nilclass in _posts/2014-08-01-
welcome-to-jekyll.markdown
jekyll 2.2.0 | error: undefined method `[]' for nil:nilclass

解决办法:在项目的配置文件里面需要设置highlighter:rouge/pygments,传送门

2.下载rubygems问题

error: could not find a valid gem 'jekyll' (>= 0), here is why:
      unable to download data from https://rubygems.org/ - ssl_connect returned=1 errno=0 state=sslv3 read server ce
 rtificate b: certificate verify failed (https://rubygems.global.ssl.fastly.net/quick/marshal.4.8/jekyll-1.3.0.gemspec.rz
 )

解决办法:下载安全证书文件,在命令行运行下面的命令,如果提示curl不是外部或内部指定命令,则是你的电脑没有安装curl插件,需要下载该插件安装,很棒的一个教程,传送门

 curl http://curl.haxx.se/ca/cacert.pem -o cacert.pem

3.安装ruby不成功,提示错误,可以试试淘宝提供的国内镜像传送门

 那么怎么通过github创建自己独有的个人网站呢?

1.下载git客户端,下载地址,下载后会有github图形界面客户端和git shell命令行工具两个,咱们使用git shell。

2.在git shell客户端输入

git init

来初始化项目;

git checkout --orphan gh-pages

创建一个gh-pages分支,该分支用来存放你的博客的所有文件,并且只能为该名称,因为github.com默认创建分支就是该名称;

git add .
git commit -a -m'just a test'

开始准备发布项目,记住,不要漏掉后面的英文小数点;

git remote add origin https://github.com/username/projectname.git
git push origin gh-pages

这样的话你的项目就创建成功。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网