如果我在GitHub存储库中有一个。html文件,例如运行一组JavaScript测试,有什么方法可以直接查看该页面,从而运行测试?
例如,我是否可以看到jQuery测试套件生成的测试结果,而不需要下载或将repo复制到本地驱动器并在那里运行?
我知道这基本上会把GitHub放在静态内容托管业务中,但话又说回来,他们只需要改变他们的mime类型从文本/纯文本/html。
如果我在GitHub存储库中有一个。html文件,例如运行一组JavaScript测试,有什么方法可以直接查看该页面,从而运行测试?
例如,我是否可以看到jQuery测试套件生成的测试结果,而不需要下载或将repo复制到本地驱动器并在那里运行?
我知道这基本上会把GitHub放在静态内容托管业务中,但话又说回来,他们只需要改变他们的mime类型从文本/纯文本/html。
当前回答
Raw.github.com/user/repository已经不存在了
要链接,href到github中的源代码,你必须使用github链接到原始源代码,以这种方式:
raw.githubusercontent.com/user/repository/master/file.extension
例子
<html>
...
...
<head>
<script src="https://raw.githubusercontent.com/amiahmadtouseef/tutorialhtmlfive/master/petdecider/script.js"></script>
...
</head>
<body>
...
</html>
其他回答
你可以分支gh-pages来运行你的代码或尝试这个扩展(Chrome, Firefox): https://github.com/ryt/githtml
如果你需要的是测试,你可以将JS文件嵌入到: http://jsperf.com/
Raw.github.com/user/repository已经不存在了
要链接,href到github中的源代码,你必须使用github链接到原始源代码,以这种方式:
raw.githubusercontent.com/user/repository/master/file.extension
例子
<html>
...
...
<head>
<script src="https://raw.githubusercontent.com/amiahmadtouseef/tutorialhtmlfive/master/petdecider/script.js"></script>
...
</head>
<body>
...
</html>
Github有一个名为Github pages的静态页面托管服务,你可以在设置下找到它,然后选择页面,并选择你想要为页面使用的分支并点击保存。
我想在github编辑HTML和js,并有一个预览。 我想在github中做它,有即时提交和保存。
尝试rawgithub.com,但rawgithub.com不是实时的(它的缓存每分钟刷新一次)。
所以我很快想出了自己的解决方案:
Node.js解决方案:https://github.com/shimondoodkin/rawgithub
我的项目Ratio.js也遇到了同样的问题,下面是我所做的。
问题: Github.com通过将内容类型/MIME设置为纯文本来防止文件在查看源代码时呈现/执行。
解决方案: 使用网页导入文件。
例子:
使用jsfiddle.net或jsbin.com在线创建一个网页,然后保存它。 在Github.com中导航到您的文件,并单击“raw”按钮以获得文件的直接链接。 从那里,使用适当的标记和属性导入文件。
<!DOCTYPE>
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen" />
</head>
<body>
<h1 id="qunit-header">QUnit example</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
<script type="text/javascript" src="https://raw.github.com/LarryBattle/Ratio.js/master/src/Ratio.js"></script>
<script type="text/javascript" src="https://raw.github.com/LarryBattle/Ratio.js/master/tests/js/Ratio-testcases.js"></script>
</body>
</html>
现场演示: http://jsfiddle.net/jKu4q/2/
注意:对于jsfiddle.net,您可以通过在url末尾添加show来直接访问结果页面。 像这样:http://jsfiddle.net/jKu4q/2/show
还是……你可以创建一个项目页面,并从那里渲染你的HTML文件。 您可以在http://pages.github.com/上创建一个项目页面。
创建完成后,您可以通过http://*accountName*.github.com/*projectName*/访问该链接 例如:http://larrybattle.github.com/Ratio.js/