本文共 4793 字,大约阅读时间需要 15 分钟。
本文翻译自:
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 , without downloading or cloning the repo to my local drive and running them there? 例如,我可以以某种方式实际看到由生成的测试结果,而无需将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 from to text/html
. 我知道这基本上会把GitHub放在静态内容托管业务中,但是再一次,他们只需要将他们的mime-type从更改为text/html
。
参考:
I had the same problem for my project and here's what I did. 我的项目遇到了同样的问题,这就是我所做的。
Problem: Github.com prevents files from rendering/executing when the source is viewed by setting the content type/MIME to plain text. 问题: Github.com通过将内容类型/ 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 Github.com and click the 'raw' button to get the direct link to the file. 导航到Github.com中的文件,然后单击“原始”按钮以获取文件的直接链接。 From there, import the file using the appropriate tag and attribute. 从那里,使用适当的标记和属性导入文件。
QUnit example
test markup, will be hidden
Live Demo: 现场演示: :
Note: Note for jsfiddle.net you can get direct access to the result page by adding show
to the end of the url. 注意:请注意,对于jsfiddle.net,您可以通过将show
添加到url的末尾来直接访问结果页面。 Like so: 像这样: :
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 through http://*accountName*.github.com/*projectName*/
Example: 一旦创建就可以再通过访问该链接http://*accountName*.github.com/*projectName*/
例子:
You can either branch gh-pages to run your code or try this extension (Chrome, Firefox): 您可以分支gh页面来运行您的代码或尝试此扩展程序(Chrome,Firefox): :
If what you need are tests, you could embed your JS files into: 如果你需要的是测试,你可以将你的JS文件嵌入: :
There is a new tool called , which does exactly what you want. 有一个名为的新工具,可以完全满足您的需求。 Just prepend http://htmlpreview.github.com/?
只是前面http://htmlpreview.github.com/?
to the URL of any HTML file, eg 到任何HTML文件的URL,例如
Note: This tool is actually a github.io page and is not affiliated with github as a company. 注意:此工具实际上是一个github.io页面,并且不与github作为公司关联。
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,虽然它与其他浏览器的工作方式类似javascript:top.location="http://htmlpreview.github.com/?"+document.URL
对于URL类型javascript:top.location="http://htmlpreview.github.com/?"+document.URL
You might want to use . 您可能想使用 。 It supports GitHub, Bitbucket, Gitlab and GitHub gists. 它支持GitHub,Bitbucket,Gitlab和GitHub。
https://raw.githubusercontent.com/[user]/[repository]/[branch]/[filename.ext]
In your case .html
extension 在您的情况下.html
扩展名
Development (throttled) 发展(受限制)
https://raw.githack.com/[user]/[repository]/[branch]/[filename.ext]
Production (CDN) 生产(CDN)
https://rawcdn.githack.com/[user]/[repository]/[branch]/[filename.ext]
In your case .html
extension 在您的情况下.html
扩展名
also supports other services: 还支持其他服务:
https://bitbucket.org/[user]/[repository]/raw/[branch]/[filename.ext]
Development (throttled) 发展(受限制)
https://bb.githack.com/[user]/[repository]/raw/[branch]/[filename.ext]
Production (CDN) 生产(CDN)
https://bbcdn.githack.com/[user]/[repository]/raw/[branch]/[filename.ext]
https://gitlab.com/[user]/[repository]/raw/[branch]/[filename.ext]
Development (throttled) 发展(受限制)
https://gl.githack.com/[user]/[repository]/raw/[branch]/[filename.ext]
Production (CDN) 生产(CDN)
https://glcdn.githack.com/[user]/[repository]/raw/[branch]/[filename.ext]
https://gist.githubusercontent.com/[user]/[gist]/raw/[revision]/[filename.ext]
Development (throttled) 发展(受限制)
https://gist.githack.com/[user]/[gist]/raw/[revision]/[filename.ext]
Production (CDN) 生产(CDN)
https://gistcdn.githack.com/[user]/[gist]/raw/[revision]/[filename.ext]
Update: rawgit was discontinued 更新:rawgit已停产
转载地址:http://ewjnb.baihongyu.com/