zoukankan      html  css  js  c++  java
  • jekyll本地环境搭建(Windows)

    序:最近一直在搞Github建站,所以一直没机会写文章,那边的环境虽然搞好了,但是网站的界面却是个问题,不想用别人的,总想自己设计个,却感觉没经验吧,就一直耽搁了。所以也就没心情在那边写文章,很久没写了,闷得很,一直没机会把建站的过程总结分享下,今天突然兴起,还是来这里写写吧~

    PS:本人一般使用win xp,所以下文都是针对 win xp系统的,一般情况下对于win系列系统都是适用的。至于linux/unix系统,本人很少玩,有机会试试。

    一、配置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下

    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所依赖的东西,由于是联网安装,所以存在连接速度等网络问题,如果出现错误,在确认前面安装步骤正常的情况下请多尝试,耐心等待!!!事后添加[2013-10-08]:修改gem命令代码源为ruby.taobao.org速度应该会较快的,具体设置见:http://ruby.taobao.org/):

    C:>gem install jekyll
    Fetching: liquid-2.5.2.gem (100%)
    Fetching: fast-stemmer-1.0.2.gem (100%)
    Temporarily enhancing PATH to include DevKit...
    Building native extensions.  This could take a while...
    Fetching: classifier-1.3.3.gem (100%)
    Fetching: directory_watcher-1.4.1.gem (100%)
    Fetching: syntax-1.0.0.gem (100%)
    Fetching: maruku-0.6.1.gem (100%)
    Fetching: yajl-ruby-1.1.0-x86-mingw32.gem (100%)
    Fetching: posix-spawn-0.3.6.gem (100%)
    Building native extensions.  This could take a while...
    Fetching: pygments.rb-0.5.2.gem (100%)
    Fetching: highline-1.6.19.gem (100%)
    Fetching: commander-4.1.5.gem (100%)
    Fetching: safe_yaml-0.7.1.gem (100%)
    Fetching: colorator-0.1.gem (100%)
    Fetching: redcarpet-2.2.2.gem (100%)
    Building native extensions.  This could take a while...
    Fetching: jekyll-1.2.0.gem (100%)
    Successfully installed liquid-2.5.2
    Successfully installed fast-stemmer-1.0.2
    Successfully installed classifier-1.3.3
    Successfully installed directory_watcher-1.4.1
    Successfully installed syntax-1.0.0
    Successfully installed maruku-0.6.1
    Successfully installed yajl-ruby-1.1.0-x86-mingw32
    Successfully installed posix-spawn-0.3.6
    Successfully installed pygments.rb-0.5.2
    Successfully installed highline-1.6.19
    Successfully installed commander-4.1.5
    Successfully installed safe_yaml-0.7.1
    Successfully installed colorator-0.1
    Successfully installed redcarpet-2.2.2
    Successfully installed jekyll-1.2.0
    15 gems installed
    Installing ri documentation for liquid-2.5.2...
    Installing ri documentation for fast-stemmer-1.0.2...
    Installing ri documentation for classifier-1.3.3...
    Installing ri documentation for directory_watcher-1.4.1...
    Installing ri documentation for syntax-1.0.0...
    Installing ri documentation for maruku-0.6.1...
    Couldn't find file to include 'MaRuKu.txt' from lib/maruku.rb
    Installing ri documentation for yajl-ruby-1.1.0-x86-mingw32...
    Installing ri documentation for posix-spawn-0.3.6...
    Installing ri documentation for pygments.rb-0.5.2...
    Installing ri documentation for highline-1.6.19...
    Installing ri documentation for commander-4.1.5...
    Installing ri documentation for safe_yaml-0.7.1...
    Installing ri documentation for colorator-0.1...
    Installing ri documentation for redcarpet-2.2.2...
    Installing ri documentation for jekyll-1.2.0...
    Installing RDoc documentation for liquid-2.5.2...
    Installing RDoc documentation for fast-stemmer-1.0.2...
    Installing RDoc documentation for classifier-1.3.3...
    Installing RDoc documentation for directory_watcher-1.4.1...
    Installing RDoc documentation for syntax-1.0.0...
    Installing RDoc documentation for maruku-0.6.1...
    Couldn't find file to include 'MaRuKu.txt' from lib/maruku.rb
    Installing RDoc documentation for yajl-ruby-1.1.0-x86-mingw32...
    Installing RDoc documentation for posix-spawn-0.3.6...
    Installing RDoc documentation for pygments.rb-0.5.2...
    Installing RDoc documentation for highline-1.6.19...
    Installing RDoc documentation for commander-4.1.5...
    Installing RDoc documentation for safe_yaml-0.7.1...
    Installing RDoc documentation for colorator-0.1...
    Installing RDoc documentation for redcarpet-2.2.2...
    Installing RDoc documentation for jekyll-1.2.0...
    
    C:>jekyll -v
    jekyll 1.2.0

    三、使用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:	estjekyll>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

    如上可见配置文件是_config.yml,网站的端口是4000,通过http://localhost:4000来访问即可。

    PS:以上安装完后,就可以自由拷贝到别的同类系统中配置并运行了(jekyll是被安装在Ruby目录下),网上有外国网友分享了此类东东,不过外国的东东多少跟我们有些出入,有兴趣的朋友可以试试(我暂时还没试过)。

    参考资料:

    http://www.madhur.co.in/blog/2011/09/01/runningjekyllwindows.html

    http://jekyllrb.com/

  • 相关阅读:
    ButterKnife 原理解析
    有关java之反射的使用
    Integer 与 int 中的 ==
    下拉框、多选框、单选框 通过TagHelper绑定数据
    动态构建视图表单
    添加我的应用中的后台图标
    标准服务接口示例代码
    .net Core下的 常用方法
    使用Redirect跳转
    标准表单提交示例代码
  • 原文地址:https://www.cnblogs.com/yevon/p/3308158.html
Copyright © 2011-2022 走看看