将生成的 jekyll 发布到 gh-pages 并且不覆盖 _site 中的 .git

发布于 2024-12-06 10:16:15 字数 680 浏览 3 评论 0原文

我正在使用 jekyll 直接在 Github 的 gh-pages 分支上发布静态站点。我遇到的问题是,每次运行

$ jekyll --no-auto /Users/khinester/Sites/tzm/

此命令都会覆盖 .git 目录,并且我必须重新创建此目录:

$ git init-db
$ git add remote ..
$ git add .
$ git commit -a -m 'message'
$ git branch gh-pages && git checkout gh-pages
etc..
$ git push -f github gh-pages

基本上我有包含生成博客所需文件的 master 分支和显示实际博客的 gh-pages 分支。

另请注意,我必须强行推动这一点。

如果还能够对更新进行版本控制,那就太好了!

我已阅读 https://github.com/mojombo/jekyll/wiki/Deployment 但这似乎比我现在所做的步骤更多。

有没有更好的方法来做到这一点或者我错过了什么。

I am using jekyll to publish a static site directly on gh-pages branch in Github. The issue I have is that every time I run

$ jekyll --no-auto /Users/khinester/Sites/tzm/

this overwrites the .git directory and I have to recreate this:

$ git init-db
$ git add remote ..
$ git add .
$ git commit -a -m 'message'
$ git branch gh-pages && git checkout gh-pages
etc..
$ git push -f github gh-pages

basically i have the master branch containing the files needed to generate the blog and gh-pages branch which displays the actual blog.

and also note that i have to force push this.

it will be nice to have also be able to version control the updates!

i have read the https://github.com/mojombo/jekyll/wiki/Deployment but this seems has more steps then what i do now.

is there a better way to do this or have i missing something.

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

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

发布评论

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

评论(3

梦途 2024-12-13 10:16:15

Jekyll 有一个名为 keep_files 的配置数组。当 Jekyll 重建站点时,该数组中的所有内容都将保留。

这是添加的位置:https://github.com/mojombo/jekyll/pull/630。搜索 keep_files 的问题将揭示更多它的黑魔法。

.git 和 .svn 文件默认添加到 keep_files 中,因此这不再是问题。

Jekyll has a config array called keep_files. Everything in that array will be kept when Jekyll rebuilds the site.

Here's where it was added: https://github.com/mojombo/jekyll/pull/630. Searching the issues for keep_files will reveal more of its black magic.

.git and .svn files are added to keep_files by default so this shouldn't be a problem anymore.

橘和柠 2024-12-13 10:16:15

我使用 Steven Penny 的脚本来编写这个脚本,该脚本是开箱即用的,适用于项目页面,而不是用户页面。

#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR

SELF=`basename $0`
SOURCE_BRANCH="master"
DEST_BRANCH="gh-pages"
TMP_DIR="tmp"

git checkout $SOURCE_BRANCH
jekyll build -d $TMP_DIR
git checkout $DEST_BRANCH
# This will remove previous files, which we may not want (e.g. CNAME)
# git rm -qr .
cp -r $TMP_DIR/. .
# Delete this script from the output
rm ./$SELF
rm -r $TMP_DIR
git add -A
git commit -m "Published updates"
# May not want to push straight away
# git push origin master
git checkout $SOURCE_BRANCH

I used Steven Penny's script to write this one, which out of the box is for Project Pages, not User Pages.

#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR

SELF=`basename $0`
SOURCE_BRANCH="master"
DEST_BRANCH="gh-pages"
TMP_DIR="tmp"

git checkout $SOURCE_BRANCH
jekyll build -d $TMP_DIR
git checkout $DEST_BRANCH
# This will remove previous files, which we may not want (e.g. CNAME)
# git rm -qr .
cp -r $TMP_DIR/. .
# Delete this script from the output
rm ./$SELF
rm -r $TMP_DIR
git add -A
git commit -m "Published updates"
# May not want to push straight away
# git push origin master
git checkout $SOURCE_BRANCH
江南烟雨〆相思醉 2024-12-13 10:16:15

我使用以下 shell 脚本来提交 Hakyll 生成的站点
(在目录 _site 中)到 gh-pages 分支。脚本:

  • 不需要您切换分支...只需从 master 或您所在的任何分支运行脚本。
  • 使用主存储库;杰基尔破坏并不重要
    .git 目录,因为...它不在那里!
  • 如果什么都没有改变,什么也不做!
  • 识别新的、以前未跟踪的文件(即使现有文件没有更改)
  • 新提交添加到gh-pages分支,因此您不需要强制推。
  • 在提交消息中包含时间戳

代码如下;根据需要更新路径

export GIT_INDEX_FILE=$PWD/.git/index-deploy
export GIT_WORK_TREE=$PWD/_site
REF=refs/heads/gh-pages
git read-tree "$REF"
git add --all --intent-to-add
git diff --quiet && exit
git add --all
TREE=$(git write-tree)
COMMIT=$(git commit-tree "$TREE" -p "$REF" -m "snapshot $(date '+%y-%m-%d %H:%M')")
git update-ref "$REF" "$COMMIT"

I use the following shell script for committing a Hakyll generated site
(in directory _site) to the gh-pages branch. The script:

  • Does not require you to switch branches... just run the script from master or whatever branch you're on.
  • Uses the main repository; it does not matter that jekyll clobbers
    the .git directory because... it isn't there!
  • Does nothing if nothing has changed!
  • Recognises new, previously untracked files (even when there are no changes to existing files)
  • Adds a new commit to the gh-pages branch, so you don't need to force push.
  • Includes a timestamp in the commit message

Code follows; update paths as necessary

export GIT_INDEX_FILE=$PWD/.git/index-deploy
export GIT_WORK_TREE=$PWD/_site
REF=refs/heads/gh-pages
git read-tree "$REF"
git add --all --intent-to-add
git diff --quiet && exit
git add --all
TREE=$(git write-tree)
COMMIT=$(git commit-tree "$TREE" -p "$REF" -m "snapshot $(date '+%y-%m-%d %H:%M')")
git update-ref "$REF" "$COMMIT"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文