包括来自raw.github.com的js [英] Including js from raw.github.com

查看:138
本文介绍了包括来自raw.github.com的js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到 https://raw.github.com/...//master/.../file.js 的github.com演示页面,每次修改时都需要将 .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
code>

我无法更改。



任何人都有任何想法完成同样的事情?以某种方式允许我链接到 master 分支中的文件,而不必总是将其推送到 gh-pages 分支?



实际页面: http:// cwolves .github.com / jQuery-iMask /

<次要更新 - 我在这个确切的实例中更改了gh页面以包含.js文件,所以IE不再破碎,但仍然会喜欢任何反馈:))解决方案

我不能帮你用怂恿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

如果这个提交不是在被监视的分支中进行的,那么这个提交就会退出
THIS_BRANCH = $(git branch --no-color | sed -e'/ ^ [^ *] / d'-e's / * \(。* \)/ \ 1 /');
if [$ THIS_BRANCH!=$ WATCH_BRANCH];然后
exit 0
fi

#只有在最近的提交中观察文件发生变化时才会更新
CHANGED_FILES = $(git show --pretty =format: --name $ WATCH_BRANCH)
if $(echo$ CHANGED_FILES| grep^ $ WATCH_FILES $-q);然后
#结帐目的地分支,然后
#结帐每个观看文件的最新版本并添加到索引
git checkout -q $ DEST_BRANCH
git pull -q
SAVEIFS = $ IFS
IFS = $(echo -n|)
用于$ WATCH_FILES中的文件; do
git checkout $ WATCH_BRANCH - $ file
git add $ file> / dev / null
完成
IFS = $ SAVEIFS
#提交一次编辑消息的机会,然后返回监视的分支
LATEST_COMMIT = $(git rev-parse $ WATCH_BRANCH)
git commit -m还包括$ WATCH_BRANCH的$ LATEST_COMMIT变动
git push origin $ DEST_BRANCH
git checkout -q $ WATCH_BRANCH
fi

请注意,这是一个通用脚本,尽管我已经为您的目的在顶部指定了配置变量。可以将 $ WATCH_FILES 设置为由大括号 | (如 index)分隔的文件列表。 HTML | JS / jquery.js和



让我知道您是否有任何疑问,并且脚本是否可以帮助您!


I have a github.com demo page that is linking to https://raw.github.com/.../master/.../file.js so that I don't need to always copy the .js file over to the gh-pages branch every time it's changed. This works in every browser except IE which complains:

SEC7112: Script from https://raw.github.com/cwolves/jQuery-iMask/master/dist/jquery-imask-min.js was blocked due to mime type mismatch

This complaint is coming from the fact that the file is transferred with:

X-Content-Type-Options: nosniff
Content-Type: text/plain

which I can't change.

Anyone have any ideas how to accomplish this same thing? Somehow allowing me to link to the file in the master branch without having to always push it to the gh-pages branch?

Actual page: http://cwolves.github.com/jQuery-iMask/

(Minor update -- I changed the gh-pages in this exact instance to include the .js file, so IE is no longer broken, but would still like any feedback :))

解决方案

I can't help you with tricking IE, and I think from that angle what you are looking for is impossible (and discouraged, since that is not the purpose of Github's raw URLs).

However, you can automate committing the changes to gh-pages and pushing to make your life easier. You can do it with a post-commit hook to update the relevant files in the gh-pages branch automatically. I've cooked up such a post-commit script that watches for changes to certain files and commits them to another branch:

#!/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

Note that this is a general script, though I have specified the config vars at the top for your purposes. $WATCH_FILES can be set to a list of files delimited by braces | such as index.html|js/jquery.js. Paths must be specified relative to the root of the repo.

Let me know if you have any questions, and if the script helps you!

这篇关于包括来自raw.github.com的js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆