How do I push jekyll _site directory to gh-pages branch, and leave the source in master?

扶醉桌前 提交于 2020-01-01 04:21:29

问题


I have a basic jekyll site consisting of pages (not posts) but, because I wanted to sort the pages when I listed them, I had to use the Jekyll-Sort plugin (kinda weird sorting pages is not built in to jekyll).

Because I'm using a plugin, I can't leverage GitHub's auto jekylling. So I'd like to push the source code of the project to the master branch and just the _site directory to the gh-pages branch.

I can't figure out how to do this - I tried adding a git repo inside the _site directory to push that to gh-pages but every time I run jekyll it erases that entire directory and I lose the .git folder.

Any suggestions? Or a way to natively sort?


回答1:


A less painful solution:

  1. Checkout your branch, where your build-source is located (maybe src, or master)
  2. (Optional: Add _site to your .gitconfig, so it get's ignored, if not already done)
  3. Remove all content of the _site directory:

    $ rm -r _site/*

  4. Clone your repo's gh-pages branch into the _site directory:

    $ git clone -b gh-pages `git config remote.origin.url` _site

Final steps: Just let jekyll build, do commit & push:

$ jekyll build,

cd into _site:

$ cd _site,

target all files for commit:

$ git add -A,

commit them:

git commit -am 'Yeah. Built from subdir'

and push your site to GitHub-Pages:

git push.




回答2:


I did this for a while myself with a shell script.

Solution 1.

Create a .gitignore that excludes the _site/ folder. Then have your shell script check whether you are on master, if so, add all changed files and commit them. Then move the _site/ folder to a temporary folder. Switch to the gh-pages branch and copy the temporary folder over. Add all and commit. Push both master & gh-pages branch.

Solution 2. Copy the contents of the _site/ folder to another repo that is an exact clone of the repo you are working with but checked out on the gh-pages branch. Then simply push the master branch from the source repo and the gh-pages branch from the other repo



来源:https://stackoverflow.com/questions/17835937/how-do-i-push-jekyll-site-directory-to-gh-pages-branch-and-leave-the-source-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!