Windows环境下的jekyll本地搭建
一、配置ruby环境
由于jekyll是用ruby语言写的一个静态网页生成工具,所以要搭建jekyll本地环境就需要先配置好ruby环境。
1)去官网下载Ruby:https://www.ruby-lang.org/zh_cn/downloads/,可以是安装包类型,也可以是解压版的。
2)如果是安装版,则默认会给你配置系统环境变量,如果是解压版的,则需要自己配置系统环境变量。虽然本人喜欢解压版的,但由于本人功力还不够,发现解压版的缺少很多必要的东东,无奈只能罢了。(当然如果一定要解压版的,就把别人安装好的拷过来吧!)
3)鉴于本人是初学者吧,而且官方推荐不知道如何安装的,就选择RubyInstaller(这 种安装方式除 Ruby 之外,捆绑一些额外的资源库。)。所以上面两步就略过了,呵呵,下载了“rubyinstaller-1.9.3-p429.exe”,记得安装的时候选 上“Add Ruby executables to your PATH”(添加系统环境变量),我这里安装到了C:\Ruby下,我的是32位系统!
4)下载DevKit,解压进行执行相关命令(至于为啥,我还不懂,这个是win系统下必要的步骤)。我解压到了C:\devkit下,打开cmd,切换到C:\devkit下,分步执行如下红色字样命令,出现如下提示表示安装成功了:
C:\>cd devkit C:\devkit>ruby dk.rb init [INFO] found RubyInstaller v1.9.3 at C:/Ruby Initialization complete! Please review and modify the auto-generated 'config.yml' file to ensure it contains the root directories to all of the installed Rubies you want enhanced by the DevKit. C:\devkit>ruby dk.rb install [INFO] Updating convenience notice gem override for 'C:/Ruby' [INFO] Installing 'C:/Ruby/lib/ruby/site_ruby/devkit.rb'
二、安装jekyll(需要联网安装)
打开cmd,执行如下红色字样命令(gem命令已在系统环境中,后面的jekyll亦如此),出现如下类似信息表示安装成功(这里会安装jekyll所依赖的东西,由于是联网安装,所以存在连接速度等网络问题,如果出现错误,在确认前面安装步骤正常的情况下请多尝试,耐心等待!!!):
C:\Users\Administrator>gem install jekyll Fetching: liquid-2.5.2.gem (100%) Successfully installed liquid-2.5.2 Fetching: fast-stemmer-1.0.2.gem (100%) Temporarily enhancing PATH to include DevKit... Building native extensions. This could take a while... Successfully installed fast-stemmer-1.0.2 Fetching: classifier-1.3.3.gem (100%) Successfully installed classifier-1.3.3 Fetching: directory_watcher-1.4.1.gem (100%) Successfully installed directory_watcher-1.4.1 Fetching: syntax-1.0.0.gem (100%) Successfully installed syntax-1.0.0 Fetching: maruku-0.6.1.gem (100%) Successfully installed maruku-0.6.1 Fetching: yajl-ruby-1.1.0-x86-mingw32.gem (100%) Successfully installed yajl-ruby-1.1.0-x86-mingw32 Fetching: posix-spawn-0.3.6.gem (100%) Building native extensions. This could take a while... Successfully installed posix-spawn-0.3.6 Fetching: pygments.rb-0.5.2.gem (100%) Successfully installed pygments.rb-0.5.2 Fetching: highline-1.6.19.gem (100%) Successfully installed highline-1.6.19 Fetching: commander-4.1.5.gem (100%) Successfully installed commander-4.1.5 Fetching: safe_yaml-0.7.1.gem (100%) Successfully installed safe_yaml-0.7.1 Fetching: colorator-0.1.gem (100%) Successfully installed colorator-0.1 Fetching: redcarpet-2.3.0.gem (100%) Building native extensions. This could take a while... Successfully installed redcarpet-2.3.0 Fetching: jekyll-1.2.1.gem (100%) Successfully installed jekyll-1.2.1 Parsing documentation for liquid-2.5.2 Installing ri documentation for liquid-2.5.2 Parsing documentation for fast-stemmer-1.0.2 unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/stemmer.so, skipping Installing ri documentation for fast-stemmer-1.0.2 Parsing documentation for classifier-1.3.3 Installing ri documentation for classifier-1.3.3 Parsing documentation for directory_watcher-1.4.1 Installing ri documentation for directory_watcher-1.4.1 Parsing documentation for syntax-1.0.0 Installing ri documentation for syntax-1.0.0 Parsing documentation for maruku-0.6.1 Couldn't find file to include 'MaRuKu.txt' from lib/maruku.rb Installing ri documentation for maruku-0.6.1 Parsing documentation for yajl-ruby-1.1.0-x86-mingw32 unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/yajl/1.8/yajl.so, skip ping unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/yajl/1.9/yajl.so, skip ping Installing ri documentation for yajl-ruby-1.1.0-x86-mingw32 Parsing documentation for posix-spawn-0.3.6 Installing ri documentation for posix-spawn-0.3.6 Parsing documentation for pygments.rb-0.5.2 Installing ri documentation for pygments.rb-0.5.2 Parsing documentation for highline-1.6.19 Installing ri documentation for highline-1.6.19 Parsing documentation for commander-4.1.5 Installing ri documentation for commander-4.1.5 Parsing documentation for safe_yaml-0.7.1 Installing ri documentation for safe_yaml-0.7.1 Parsing documentation for colorator-0.1 Installing ri documentation for colorator-0.1 Parsing documentation for redcarpet-2.3.0 unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/redcarpet.so, skipping Installing ri documentation for redcarpet-2.3.0 Parsing documentation for jekyll-1.2.1 Installing ri documentation for jekyll-1.2.1 15 gems installed C:\Users\Administrator>jekyll -v jekyll 1.2.1
三、使用jekyll创建网站并运行
jekyll是一个静态网页生成工具,那么必然有所谓的“源码”,或者说jekyll可以把你写的有一定格式的文件转换成静态网页。通过 jekyll -h查看帮助可以发现有new参数,让jekyll帮助创建一个网站,即在cmd中执行“jekyll new 网站名”即可,jekyll会在当前目录下新建一个以网站名为名的文件夹,里面的是自动生成的一个简单的网站内容。
为了能够让这里网站正常运行,这里需要删除_post文件夹里的文件(应该有一个xxxx-xx-xx-welcome-to- jekyll.markdown字样的文件),因为这个文件内部使用了语法高亮插件(另外不删,则可以修改配置文件禁用该语法高亮插件,即修改根目录下 _config.yml中的pygments: true为false便可。),这个需要另外安装,不再本文范围内,不删会导致生成的静态页面有问题,因时间有限本文暂不提此问题。
另外还会存在编码上的问题,但现在只要不在里面用中文,就暂时没事,后面文章再提。
最后切换到新建的网站目录下,执行jekyll serve来启动网站,默认生成的静态网页等相关资源会放入_site文件夹。命令执行结果如下:
C:\testjekyll>jekyll serve Configuration file: C:/testjekyll/_config.yml Source: C:/testjekyll Destination: C:/testjekyll/_site Generating... done. [2013-09-08 17:34:51] INFO WEBrick 1.3.1 [2013-09-08 17:34:51] INFO ruby 1.9.3 (2013-05-15) [i386-mingw32] [2013-09-08 17:34:51] INFO WEBrick::HTTPServer#start: pid=984 port=4000
PS:以上安装完后,就可以自由拷贝到别的同类系统中配置并运行了(jekyll是被安装在Ruby目录下),网上有外国网友分享了此类东东,不过外国的东东多少跟我们有些出入,有兴趣的朋友可以试试(我暂时还没试过)。
参考资料:
http://www.madhur.co.in/blog/2011/09/01/runningjekyllwindows.html
本文参考资料:
谢谢yevon的参考资料!