23

我刚刚为我的 Jekyll 博客创建了一个很棒的画廊,它完美地构建在我的 localhost:4000 上。但是,GitHub pages 不支持我使用的 Jekyll Gallery Generator 插件:https ://github.com/ggreer/jekyll-gallery-generator

我阅读了有关使用 FTP(上传 _site 目录)在传统主机上托管 Jekyll 的替代方法http://jekyllrb.com/docs/deployment-methods/但是,与其重新配置我的整个站点和托管,这会很棒即使我使用的是不受支持的插件,是否可以以某种方式使用 GitHub Pages。

什么是解决方法?

4

2 回答 2

47

根据您处理的是用户/组织 ( UO ) 站点还是项目站点 ( P ),请执行以下操作:

  1. 从您的工作文件夹git init
  2. git remote add origin git@github.com:userName/userName.github.io.git( UO ) 或git remote add origin git@github.com:userName/repositoryName.git( P )
  3. jekyll new .创建您的代码库
  4. _config.yml中,将baseurl参数设置为baseurl: ''( UO ) 或baseurl: '/repositoryName'( P )
  5. .gitignore添加_site,它将在另一个分支中进行版本控制
  6. jekyll build将创建目标文件夹和构建站点。
  7. git checkout -b sources( UO ) 或git checkout master( P )
  8. git add -A
  9. git commit -m "jekyll base sources"提交你的源代码
  10. git push origin sources( UO ) 或git push origin master( P ) 将您的资源推送到适当的分支
  11. cd _site
  12. touch .nojekyll, 这个文件告诉 gh-pages 不需要构建
  13. git init初始化存储库
  14. git remote add origin git@github.com:userName/userName.github.io.git( UO ) 或git remote add origin git@github.com:userName/repositoryName.git( P )
  15. git checkout master( UO ) 或git checkout -b gh-pages( P ) 将此存储库放在适当的分支上
  16. git add -A
  17. git commit -m "jekyll first build"提交您的网站代码
  18. git push origin master( UO ) 或git push origin gh-pages( P )

你现在有了像Octopress一样的东西。看看他们的 rake 文件,里面有一些很好的评论。

于 2015-01-31T13:37:20.040 回答
4

更好的方法是将 Travis 配置为使用不支持的插件自动部署 jekyll。按照Travis 入门指南为您的 repo 启用 Travis。

script/cibuild使用以下内容创建

#!/usr/bin/env bash
set -e # halt script on error

bundle exec jekyll build
touch ./_site/.nojekyll # this file tells gh-pages that there is no need to build

.travis.yml使用以下内容创建(根据需要修改)

language: ruby
rvm:
- 2.3.3

before_script:
 - chmod +x ./script/cibuild # or do this locally and commit

# Assume bundler is being used, therefore
# the `install` step will run `bundle install` by default.
script: ./script/cibuild

# branch whitelist, only for GitHub Pages
branches:
  only:
  - master

env:
  global:
  - NOKOGIRI_USE_SYSTEM_LIBRARIES=true # speeds up installation of html-proofer

sudo: false # route your build to the container-based infrastructure for a faster build

deploy:
  provider: pages
  skip_cleanup: true
  keep-history: true
  local_dir: _site/  # deploy this directory containing final build
  github_token: $GITHUB_API_KEY # Set in travis-ci.org dashboard
  on:
    branch: master

部署步骤(每次推送后):

  1. 将使用我们script/cibuild_site目录中的自定义脚本创建构建
  2. _site将被推送到gh-pages分支。
  3. github页面将按原样提供站点而无需再次构建它(因为.nojekyll文件)

参考:我的存储库https://github.com/armujahid/armujahid.me/正在使用这种方法使用 Travis CI 进行持续集成

于 2018-07-21T09:17:07.687 回答