使用Jekyll在本地测试GitHub Pages网站

2021/04/21 0 GitHub 共 1517 字,约 5 分钟
臭粑粑大朱

使用Jekyll在本地测试 GitHub Pages 网站

一、安装 Jeklly

注意:本人系统(Windows10 64位)

建议使用 Bundler 安装和运行 Jekyll。Bundler 管理 Ruby gem 依赖项,减少 Jekyll 构建错误,并防止与环境相关的错误。要安装 Bundler,请执行以下操作:

1. 安装 Ruby。

Windows 系统下 Ruby 安装包下载地址

检查是否安装成功:

ruby -v

其他系统安装详情请参见“安装 Ruby ”。

2. 安装 Bundler。

gem install bundler

详情请参见“安装 Bundler ”。

3. 官方对 Gems、Gemfile、Bundler 的简单讲解

官方对相关术语解释说明点击此处查看

一个 Gemfile 的简单示例:

source "https://rubygems.org"

gem "jekyll"

group :jekyll_plugins do
  gem "jekyll-feed"
  gem "jekyll-seo-tag"
end

二、创建一个 Jekyll 网站。

1. 只需几行命令,赶紧来体验吧!

  1. Jekyll Helloworld 程序可参考 Jekyll 官网
gem install bundler jekyll
jekyll new my-awesome-site
cd my-awesome-site
bundle exec jekyll serve

# => 打开浏览器 http://localhost:4000
  1. 在本地运行您的 Jekyll 网站,参考 GitHub Docs 官网。
bundle install
bundle exec jekyll serve

> Configuration file: /Users/octocat/my-site/_config.yml
>            Source: /Users/octocat/my-site
>       Destination: /Users/octocat/my-site/_site
> Incremental build: disabled. Enable with --incremental
>      Generating...
>                    done in 0.309 seconds.
> Auto-regeneration: enabled for '/Users/octocat/my-site'
> Configuration file: /Users/octocat/my-site/_config.yml
>    Server address: http://127.0.0.1:4000/
>  Server running... press ctrl-c to stop.
# 调试过程中遇到如下报错:
# 报错:No source of timezone data could be found
# 通过百度解决了此问题,由于第一次接触这些技术,暂时无经历了解,导致原因不明。
# Gemfile配置添加如下配置即可:
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]

# 然后执行:
bundle update
bundle exec jekyll serve

三、更新 GitHub Pages gem 。

按照官方说法,Jekyll 是一个活跃的开源项目,经常更新。如果您计算机上的 github-pages gem 与 GitHub Pages 服务器上的 gem 相比已经过期了,则您的站点在本地构建时可能与在 GitHub 上发布的站点看起来有所不同。为避免这种情况,请定期更新 github-pages 计算机上的 gem 。

  • 如果您安装了 Bundler

    bundle update github-pages
    
  • 如果您没有安装 Bundler

    gem update github-pages
    

文档信息

查找

    Table of Contents