开发者

Publish Jekyll Site To Git Repository

Every time I run Jekyll it destroys开发者_如何学JAVA the entire contents of the destination folder. The problem with this is that my destination directory is a small git repo from which I use to push to my actual server. Is there a way to stop Jekyll deleting the Git files so that I don't have to generate the contents then copy them over?


You could have:

  • your git repo elsewhere (i.e. not in the directory affected by a Jekyll deployment)
  • have your script pushing that git repo to your server specify a GIT_WORK_TREE variable with the destination folder as value

In other words, a .git don't have to be necessary in the working tree directory itself.
It can be elsewhere, and your script can refer to the actual working tree through GIT_WORK_TREE or through a --work-tree=<path> option.

If your script is part of the destination directory where Jenkyll copies/erases files, you can do the opposite, and mention where the .git actually is with GIT_DIR variable or with --git-dir=<path> option.

To have new --work-dir as default options to your repo, you can use git-config --add core.worktree ../PATH/, where PATH - path to actual working directory relative to .git.


Have you had a look at the Deployment section of the Jekyll wiki? - https://github.com/mojombo/jekyll/wiki/Deployment. It clearly explains Jekyll deployment steps.

And why are you pushing from the destination? That is bad! Push it from some other clone.


I also want this setup. Found this pull request to fix Jekyll, making it not delete the .git dir: https://github.com/mojombo/jekyll/pull/337

Read my comment there, as:

  1. the fix is actually slightly broken (make it .git not .git$)
  2. I believe a better solution would be to have this as a configuration variable, to handle other files like .svn.

Anyway, my Jekyll line now reads: dest_files << file unless file =~ /\/\.{1,2}$/ || file =~/\/\.git/

Works great! I'm even using octopress (just change your deploy_dir to be public) and comment out the following lines in Rakefile:

    #  (Dir["#{deploy_dir}/*"]).each { |f| rm_rf(f) }
    #  Rake::Task[:copydot].invoke(public_dir, deploy_dir)
    #  puts "\n## copying #{public_dir} to #{deploy_dir}"
    #  cp_r "#{public_dir}/.", deploy_dir

Now your public dir (instead of _deploy dir) can be your github repo to publish your site (submodule of a branch or my parent repo in my case)

Seems senseless to have public and _deploy with octopress, but I'm happy to hear other reasons why to split public and _deploy dirs - besides Jekyll deleting the .git dir. (I read through the full commit history of octopress, but couldn't find any explanation for why its done this way)


I actually used

git clone --separate-git-dir repo git@github....

and sovled this problem.


@manojlds, I'm not sure I understand, TPW's default _config.yml (Which I've customized) shows the location of the _site directory as ".", inside of the blog directory which also contains the Git repo. Is there a way to move this directory so that it doesn't spew files all over the place? I think I'm missing something here because either Jekyll refuses to generate anything or the above scenario happens and I have to clean up the mess that's left behind.

Do we have a best practice for where _site can (or should) be located?

Edit: Looking at it, I actually see the following:

source: . destination: ./_site

The fact that Terminal can't find the jekyll gem (installed via RVM) is probably the cause of my problem rather than the location of _site.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜