简体   繁体   English

如何配置 GitHub 以使用不受支持的 Jekyll 站点插件?

[英]How do I configure GitHub to use non-supported Jekyll site plugins?

I just created a great gallery for my Jekyll blog which builds perfectly on my localhost:4000.我刚刚为我的 Jekyll 博客创建了一个很棒的画廊,它完美地构建在我的 localhost:4000 上。 However, GitHub pages doesn't support the Jekyll Gallery Generator plug-in I am using: https://github.com/ggreer/jekyll-gallery-generator但是,GitHub 页面不支持我使用的 Jekyll Gallery Generator 插件: https : //github.com/ggreer/jekyll-gallery-generator

I read about the alternative method of hosting Jekyll on a traditional host using FTP (uploading the _site directory) http://jekyllrb.com/docs/deployment-methods/ However, rather than reconfigure my entire site and hosting, It would be great if GitHub Pages could be used somehow even though I'm using a non-supported plugin.我阅读了使用 FTP 在传统主机上托管 Jekyll 的替代方法(上传 _site 目录) http://jekyllrb.com/docs/deployment-methods/但是,与其重新配置我的整个站点和托管,不如说它会很棒如果 GitHub Pages 可以以某种方式使用,即使我使用的是不受支持的插件。

What is a workaround for this?什么是解决方法?

Depending if you deal with a User/Organization ( UO ) site or a Project site ( P ), do :取决于您处理的是用户/组织 ( UO ) 站点还是项目站点 ( P ),请执行以下操作:

  1. from your working folder git init从你的工作文件夹git init
  2. git remote add origin git@github.com:userName/userName.github.io.git ( UO ) or git remote add origin git@github.com:userName/repositoryName.git ( P ) 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 . creates your code base创建您的代码库
  4. in _config.yml , set the baseurl parameter to baseurl: '' ( UO ) or baseurl: '/repositoryName' ( P )_config.yml 中,将baseurl参数设置为baseurl: '' ( UO ) 或baseurl: '/repositoryName' ( P )
  5. in .gitignore add _site , it will be versioned in the other branch.gitignore添加_site ,它将在另一个分支中进行版本控制
  6. jekyll build will create the destination folder and build site. jekyll build将创建目标文件夹和构建站点。
  7. git checkout -b sources ( UO ) or git checkout master ( P ) git checkout -b sources ( UO ) 或git checkout master ( P )
  8. git add -A
  9. git commit -m "jekyll base sources" commit your source code git commit -m "jekyll base sources"提交你的源代码
  10. git push origin sources ( UO ) or git push origin master ( P ) push your sources in the appropriate branch git push origin sources ( UO ) 或git push origin master ( P ) 在适当的分支中推送你的源代码
  11. cd _site
  12. touch .nojekyll , this file tells gh-pages that there is no need to build touch .nojekyll ,这个文件告诉 gh-pages 不需要构建
  13. git init init the repository git init初始化存储库
  14. git remote add origin git@github.com:userName/userName.github.io.git ( UO ) or git remote add origin git@github.com:userName/repositoryName.git ( P ) 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 ) or git checkout -b gh-pages ( P ) put this repository on the appropriate branch git checkout master ( UO ) 或git checkout -b gh-pages ( P ) 将此存储库放在适当的分支上
  16. git add -A
  17. git commit -m "jekyll first build" commit your site code git commit -m "jekyll first build"提交你的站点代码
  18. git push origin master ( UO ) or git push origin gh-pages ( P ) git push origin master ( UO ) 或git push origin gh-pages ( P )

You now have something like Octopress does.你现在有像Octopress那样的东西。 Look at their rake file, there are some nice comments inside.看看他们的 rake 文件,里面有一些不错的评论。

Better way is to configure Travis to automate deployment of jekyll with non-supported plugins.更好的方法是配置 Travis 以使用不受支持的插件自动部署 jekyll。 Follow Travis getting started guide to enable Travis for your repo.按照Travis 入门指南为您的存储库启用 Travis。

Create script/cibuild with the following content使用以下内容创建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

Create .travis.yml with the following content (modify as required)使用以下内容创建.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

Deployment steps (after every push):部署步骤(每次推送后):

  1. Build will be created using our custom script script/cibuild in _site directory将使用我们在_site目录中的自定义脚本script/cibuild创建构建
  2. _site will be pushed to gh-pages branch. _site将被推送到gh-pages分支。
  3. github pages will serve site as it is without building it again (because of .nojekyll file) github 页面将按原样为站点提供服务,而无需再次构建它(因为.nojekyll文件)

Reference: My repository https://github.com/armujahid/armujahid.me/ is using this method for continuous integration using Travis CI参考:我的存储库https://github.com/armujahid/armujahid.me/正在使用这种方法使用 Travis CI 进行持续集成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM