我有一个github.com演示页面,链接到https://raw.github.com/.../master/.../file.js,这样我就不需要每次更改时总是将.js
文件复制到gh-pages
分支。这适用于所有浏览器,除了IE,它抱怨:
SEC7112:来自https://raw.github.com/cwolves/jQuery-iMask/master/dist/jquery-imask-min.js的脚本由于mime类型不匹配而被阻止
这个报错是由于文件是用:
传输的X-Content-Type-Options: nosniff
Content-Type: text/plain
我无法改变。
有谁知道如何完成同样的事情吗?以某种方式允许我链接到master
分支中的文件,而不必总是将其推送到gh-pages
分支?
实际页面:http://cwolves.github.com/jQuery-iMask/
(小更新-我在这个确切的实例中更改了h-pages以包含.js文件,因此IE不再被破坏,但仍然希望有任何反馈:))
您可以尝试使用https://rawgit.com/服务。请将rawgit.com替换为rawgit.com
Rawgit服务(原Rawgithub)已被关闭。
RawGit已经到了使用寿命的尽头2018年10月8日
上个月通过RawGit提供内容的GitHub存储库将至少持续到2019年10月。其他存储库的url不再被提供。
如果你正在使用RawGit,请尽快停止使用。
我无法帮助你欺骗IE,我认为从这个角度来看,你所寻找的是不可能的(并且不鼓励,因为这不是Github原始url的目的)。
但是,您可以自动将更改提交到gh-pages
并推送,使您的生活更轻松。您可以使用post-commit hook
来自动更新gh-pages
分支中的相关文件。我已经编写了这样一个post-commit
脚本,它监视对某些文件的更改并将它们提交到另一个分支:
#!/bin/sh
WATCH_BRANCH="master"
WATCH_FILES="jquery-imask-min.js"
DEST_BRANCH="gh-pages"
# bail out if this commit wasn't made in the watched branch
THIS_BRANCH=$(git branch --no-color | sed -e '/^[^*]/d' -e 's/* (.*)/1/');
if [ "$THIS_BRANCH" != "$WATCH_BRANCH" ]; then
exit 0
fi
# only update if watched files have changed in the latest commit
CHANGED_FILES=$(git show --pretty="format:" --name-only $WATCH_BRANCH)
if $(echo "$CHANGED_FILES" | grep "^$WATCH_FILES$" -q); then
# checkout destination branch, then
# checkout latest version of each watched file and add to index
git checkout -q $DEST_BRANCH
git pull -q
SAVEIFS=$IFS
IFS=$(echo -n "|")
for file in $WATCH_FILES; do
git checkout $WATCH_BRANCH -- $file
git add $file > /dev/null
done
IFS=$SAVEIFS
# commit with a chance to edit the message, then go back to watched branch
LATEST_COMMIT=$(git rev-parse $WATCH_BRANCH)
git commit -m "Also including changes from $WATCH_BRANCH's $LATEST_COMMIT"
git push origin $DEST_BRANCH
git checkout -q $WATCH_BRANCH
fi
请注意,这是一个通用脚本,尽管我在顶部指定了配置变量以满足您的目的。$WATCH_FILES
可以设置为用大括号|
分隔的文件列表,例如index.html|js/jquery.js
。路径必须相对于repo的根指定。
让我知道如果你有任何问题,如果脚本帮助你!
看看raw.githack.com。这项服务的灵感来自rawgit.com。我刚刚意识到,使用一个完整的框架(node.js + express.js)来做这样简单的事情,如请求代理是多余的,只使用nginx做同样的事情。
将github/gist URL中的"githubusercontent"域名块替换为"githack",然后完成!
此外,它支持bitbucket.com -只需将整个bitbucket域名替换为bb.githack.com
。
Github的原始url不是设计成一个通用的web主机。把这些东西放到合适的主机上,比如pages.github.com
现在有jsdeliver,它是开源的,免费的,快速的。并支持GitHub!https://www.jsdelivr.com/
而且它来自值得信赖的人/公司。
我这样说是因为我不确定我们是否可以信任https://raw.githack.com/
我也在努力实现这一点。然而,我似乎无法从@shelhamer得到解决方案,以在我的代码库中工作。下面是更新后的提交后钩子脚本,我用来让它工作:
#!/bin/sh
WATCH_BRANCH="master"
WATCH_FILES="jquery-imask-min.js"
DEST_BRANCH="gh-pages"
# bail out if this commit wasn't made in the watched branch
THIS_BRANCH=$(git branch --no-color | sed -e '/^[^*]/d' -e 's/* (.*)/1/');
if [ "$THIS_BRANCH" != "$WATCH_BRANCH" ]; then
exit 0
fi
# only update if watched files have changed in the latest commit
CHANGED_FILES=$(git show --pretty="format:" --name-only $WATCH_BRANCH)
if $(echo "$CHANGED_FILES" | grep "^$WATCH_FILES$" -q); then
# checkout destination branch, then
# checkout latest version of each watched file and add to index
git checkout -q $DEST_BRANCH
git pull -q
SAVEIFS=$IFS
IFS=$(echo -n "|")
for file in $WATCH_FILES; do
git checkout $WATCH_BRANCH -- $file
git add $file > /dev/null
done
IFS=$SAVEIFS
# commit with a chance to edit the message, then go back to watched branch
LATEST_COMMIT=$(git rev-parse $WATCH_BRANCH)
git commit -m "Also including changes from $WATCH_BRANCH's $LATEST_COMMIT"
git push origin $DEST_BRANCH
git checkout -q $WATCH_BRANCH
fi
我必须更新grep的使用,使regex成功匹配(-P不是Windows的Git Bash shell中包含的grep实现的选项),添加git pull
和git push origin $DEST_BRANCH
。哦,我必须提前添加目录和文件的空shell(也许只有目录就足够了?)
由于这实际上是在做推送,我认为最好将此脚本切换为post-receive脚本而不是post-commit。否则,您可能会将代码推送到从未进入主页面的高页面[如果您选择不推送它]。