本文翻译自:Can I run HTML files directly from GitHub, instead of just viewing their source?
If I have a.html
file in a GitHub repository, eg for running aa set of JavaScript tests, is there any way I can view that page directly—thus running the tests?如果我在GitHub存储库中有一个.html
文件,例如用于运行一组JavaScript测试,我有什么方法可以直接查看该页面 - 从而运行测试?
For example, could I somehow actually see the test results that would be produced by the jQuery test suite , without downloading or cloning the repo to my local drive and running them there?例如,我可以以某种方式实际看到由jQuery测试套件生成的测试结果,而无需将repo下载或克隆到我的本地驱动器并在那里运行它们吗?
I know this would basically put GitHub in the static content hosting business, but then again, they just have to change their mime-type fromtext/plain
totext/html
.我知道这基本上会把GitHub放在静态内容托管业务中,但是再一次,他们只需要将他们的mime-type从text/plain
更改为text/html
。
#1楼
参考:/question/RUKU/我可以直接从GitHub运行HTML文件-而不仅仅是查看它们的来源吗
#2楼
I had the same problem for my project Ratio.js and here's what I did.我的项目Ratio.js遇到了同样的问题,这就是我所做的。
Problem:prevents files from rendering/executing when the source is viewed by setting the content type/MIME to plain text.问题:通过将内容类型/ MIME设置为纯文本来防止在查看源时呈现/执行文件。
Solution:Have a web page import the files.解决方案:让网页导入文件。
Example:例:
Use or to create a webpage online then save it.使用或在线创建网页然后保存。Navigate to your file in and click the 'raw' button to get the direct link to the file.导航到中的文件,然后单击“原始”按钮以获取文件的直接链接。From there, import the file using the appropriate tag and attribute.从那里,使用适当的标记和属性导入文件。
<!DOCTYPE><html><head><link rel="stylesheet" href="/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="/jquery-latest.js"></script><script type="text/javascript" src="/qunit/git/qunit.js"></script> <script type="text/javascript" src="/LarryBattle/Ratio.js/master/src/Ratio.js"></script> <script type="text/javascript" src="/LarryBattle/Ratio.js/master/tests/js/Ratio-testcases.js"></script> </body></html>
Live Demo: /jKu4q/2/现场演示: http : ///jKu4q/2/
Note:Note for you can get direct access to the result page by addingshow
to the end of the url.注意:请注意,对于,您可以通过将show
添加到url的末尾来直接访问结果页面。Like so: /jKu4q/2/show像这样: http : ///jKu4q/2/show
Or....you could create a project page and render your HTML files from there.或者......你可以创建一个项目页面并从那里渲染你的HTML文件。You can create a project page at / .您可以在/上创建项目页面。
Once created you can then access the link throughhttp://*accountName*./*projectName*/
Example: /Ratio.js/一旦创建就可以再通过访问该链接http://*accountName*./*projectName*/
例子: /Ratio.js/
#3楼
You can either branch gh-pages to run your code or try this extension (Chrome, Firefox): /ryt/githtml您可以分支gh页面来运行您的代码或尝试此扩展程序(Chrome,Firefox): https : ///ryt/githtml
If what you need are tests, you could embed your JS files into: /如果你需要的是测试,你可以将你的JS文件嵌入: http : ///
#4楼
There is a new tool called GitHub HTML Preview , which does exactly what you want.有一个名为GitHub HTML Preview的新工具,可以完全满足您的需求。Just prepend/?
只是前面/?
to the URL of any HTML file, eg /?/twbs/bootstrap/blob/gh-pages/2.3.2/index.html到任何HTML文件的URL,例如/?/twbs/bootstrap/blob/gh-pages/2.3.2/index.html
Note: This tool is actually a github.io page and is not affiliated with github as a company.注意:此工具实际上是一个github.io页面,并且不与github作为公司关联。
#5楼
To piggyback on @niutech's answer, you can make a very simple bookmark snippet.为了搭上@niutech的答案,你可以制作一个非常简单的书签片段。
Using Chrome, though it works similarly with other browsers使用Chrome,虽然它与其他浏览器的工作方式类似
Right click your bookmark bar右键单击书签栏ClickAdd File单击添加文件Name it something likeGithub HTML将其命名为Github HTMLFor theURLtypejavascript:top.location="/?"+document.URL
对于URL类型javascript:top.location="/?"+document.URL
When you're on a github file view page (not ) click the bookmark link and you're golden.当你在github文件视图页面(而不是)上时,单击书签链接,你就是金色的。
#6楼
You might want to use .您可能想使用 。It supports GitHub, Bitbucket, Gitlab and GitHub gists.它支持GitHub,Bitbucket,Gitlab和GitHub。
GitHubGitHub上
Before:之前:
/[user]/[repository]/[branch]/[filename.ext]
In your case.html
extension在您的情况下.html
扩展名
After:后:
Development (throttled)发展(受限制)
/[user]/[repository]/[branch]/[filename.ext]
Production (CDN)生产(CDN)
/[user]/[repository]/[branch]/[filename.ext]
In your case.html
extension在您的情况下.html
扩展名
also supports other services:还支持其他服务:
Bitbucket到位桶
Before:之前:
/[user]/[repository]/raw/[branch]/[filename.ext]
After:后:
Development (throttled)发展(受限制)
/[user]/[repository]/raw/[branch]/[filename.ext]
Production (CDN)生产(CDN)
/[user]/[repository]/raw/[branch]/[filename.ext]
GitLabGitLab
Before:之前:
/[user]/[repository]/raw/[branch]/[filename.ext]
After:后:
Development (throttled)发展(受限制)
/[user]/[repository]/raw/[branch]/[filename.ext]
Production (CDN)生产(CDN)
/[user]/[repository]/raw/[branch]/[filename.ext]
GitHub gistsGitHub要点
Before:之前:
/[user]/[gist]/raw/[revision]/[filename.ext]
After:后:
Development (throttled)发展(受限制)
/[user]/[gist]/raw/[revision]/[filename.ext]
Production (CDN)生产(CDN)
/[user]/[gist]/raw/[revision]/[filename.ext]
Update: rawgit was discontinued更新:rawgit已停产