将 Jekyll 站点发布到 Git 存储库

发布于 2024-11-08 05:05:02 字数 118 浏览 8 评论 0原文

每次我运行 Jekyll 时,它都会破坏目标文件夹的全部内容。问题是我的目标目录是一个小的 git 存储库,我用它来推送到我的实际服务器。有没有办法阻止 Jekyll 删除 Git 文件,这样我就不必生成内容然后复制它们?

Every time I run Jekyll it destroys 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

屋檐 2024-11-15 05:05:02

您可以:

  • 您的 git 存储库在其他地方(即不在受 Jekyll 部署影响的目录中)
  • 让您的脚本将该 git 存储库推送到您的服务器指定一个 GIT_WORK_TREE 变量,并将目标文件夹作为值

换句话说,.git 在工作树目录本身中不一定是必需的。
它可以在其他地方,您的脚本可以通过 GIT_WORK_TREE 或通过 --work-tree= 选项引用实际工作树。

如果您的脚本是 Jenkyll 复制/删除文件的目标目录的一部分,您可以执行相反的操作,并使用 GIT_DIR 变量或 .git 实际所在位置。 code>--git-dir=选项。

要将新的 --work-dir 作为存储库的默认选项,您可以使用 git-config --add core.worktree ../PATH/,其中 >PATH - 相对于 .git 的实际工作目录的路径。

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.

氛圍 2024-11-15 05:05:02

您看过 Jekyll wiki 的部署部分吗? - https://github.com/mojombo/jekyll/wiki/Deployment。它清楚地解释了 Jekyll 部署步骤。

为什么你要从目的地出发?那就不好了!从其他克隆推送它。

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 2024-11-15 05:05:02

我也想要这个设定发现这个拉取请求来修复 Jekyll,使其不删除 .git 目录:
https://github.com/mojombo/jekyll/pull/337

阅读我的评论,因为:

  1. 修复实际上有点损坏(使其成为 .git 而不是 .git$)
  2. 我相信更好的解决方案是将其作为配置变量,以处理其他文件,例如 .svn。

无论如何,我的 Jekyll 行现在显示为: dest_files <<文件除非 file =~ /\/\.{1,2}$/ || file =~/\/\.git/

效果很好!我什至使用octopress(只需将您的deploy_dir更改为公共)并在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

现在您的公共目录(而不是_deploy目录)可以是您的github存储库来发布您的站点(分支或我的子模块)在我的例子中,

使用 public 和 _deploy 似乎毫无意义,但我很高兴听到分割 public 和 _deploy 目录的其他原因 - 除此之外Jekyll 删除 .git 目录。 (我通读了 octopress 的完整提交历史,但找不到任何解释为什么这样做)

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)

初见你 2024-11-15 05:05:02

我实际使用

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

并解决了这个问题。

I actually used

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

and sovled this problem.

小兔几 2024-11-15 05:05:02

@manojlds,我不确定我是否理解,TPW 的默认 _config.yml (我已自定义)将 _site 目录的位置显示为“.”,位于博客目录内,其中还包含 Git 存储库。有没有办法移动这个目录,这样它就不会把文件散得到处都是?我想我在这里遗漏了一些东西,因为要么 Jekyll 拒绝生成任何东西,要么发生上述情况,我必须清理留下的烂摊子。

对于 _site 可以(或应该)位于何处,我们是否有最佳实践?

编辑:看看它,我实际上看到以下内容:

来源:。
目的地:./_site

终端找不到 jekyll gem(通过 RVM 安装)的事实可能是我的问题的原因,而不是 _site 的位置。

@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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文