【问题标题】:How do I configure GitHub to use non-supported Jekyll site plugins?如何配置 GitHub 以使用不受支持的 Jekyll 站点插件?
【发布时间】:2015-03-30 17:13:28
【问题描述】:

我刚刚为我的 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 甚至可以以某种方式使用,那就太好了虽然我使用的是不受支持的插件。

有什么解决方法?

【问题讨论】:

    标签: github jekyll github-pages jekyll-extensions


    【解决方案1】:

    根据您处理的是用户/组织 (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 文件,里面有一些不错的 cmets。

    【讨论】:

    • 谢谢大卫,很好的回答!我的网站现在正在使用您描述的工作流程运行图库:raisingthelittleone.com 但是,我确实想提一下,如果您使用的是自定义域(例如我),那么即使项目页面 baseurl 也会保留为空白字符串。
    • 谢谢大卫。这是人生的一大进步。 Baby.create!(name: "Luna") =D
    • 这是一个非常详细的答案。但在第 15 步,情况 UO,你实际上不必git checkout master,因为你会自动成为这个分支
    • 如果你有这个设置,你如何保持主文件夹与源文件夹同步?
    • 你在这里使用两个 .gitignore 吗?每个分支一个?
    【解决方案2】:

    更好的方法是配置 Travis 以使用不受支持的插件自动部署 jekyll。按照Travis getting started 指南为您的仓库启用 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 进行持续集成

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-25
      • 2021-07-05
      • 2015-10-23
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多