博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
我可以直接从GitHub运行HTML文件,而不仅仅是查看它们的来源吗?
阅读量:2288 次
发布时间:2019-05-09

本文共 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


#1楼

参考:


#2楼

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*/例子:


    #3楼

    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文件嵌入: :


    #4楼

    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作为公司关联。


    #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,虽然它与其他浏览器的工作方式类似

    1. Right click your bookmark bar 右键单击书签栏
    2. Click Add File 单击添加文件
    3. Name it something like Github HTML 将其命名为Github HTML
    4. For the URL type javascript:top.location="http://htmlpreview.github.com/?"+document.URL 对于URL类型javascript:top.location="http://htmlpreview.github.com/?"+document.URL
    5. When you're on a github file view page ( not raw.github.com ) click the bookmark link and you're golden. 当你在github文件视图页面( 而不是raw.github.com )上时,单击书签链接,你就是金色的。

    #6楼

    You might want to use . 您可能想使用 。 It supports GitHub, Bitbucket, Gitlab and GitHub gists. 它支持GitHub,Bitbucket,Gitlab和GitHub。

    GitHub GitHub上

    Before: 之前:

    https://raw.githubusercontent.com/[user]/[repository]/[branch]/[filename.ext]

    In your case .html extension 在您的情况下.html扩展名

    After: 后:

    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: 还支持其他服务:

    Bitbucket 到位桶

    Before: 之前:

    https://bitbucket.org/[user]/[repository]/raw/[branch]/[filename.ext]

    After: 后:

    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]

    GitLab GitLab

    Before: 之前:

    https://gitlab.com/[user]/[repository]/raw/[branch]/[filename.ext]

    After: 后:

    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]

    GitHub gists GitHub要点

    Before: 之前:

    https://gist.githubusercontent.com/[user]/[gist]/raw/[revision]/[filename.ext]

    After: 后:

    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/

    你可能感兴趣的文章
    看图搞懂微服务架构
    查看>>
    详解:java工具之解析yaml文件
    查看>>
    包教包会:搭建RocketMQ双主双从同步集群,
    查看>>
    5年Java程序员,五面蚂蚁险拿offer定级P7,大厂面试不过如此?
    查看>>
    大厂面试必问!HashMap 怎样解决hash冲突?
    查看>>
    面试屡屡碰壁,痛定思痛闭关修炼!半年后4面阿里成功拿offer
    查看>>
    最全的大厂最新面试249题与笔记总结:多线程+JVM +Spring+微服务+分布式+Redis+MySQL
    查看>>
    吊!设计模式全解:6大设计原则+23种设计模式+设计模式PK+设计模式混编
    查看>>
    服!看完阿里大牛手写的Java异步编程实战笔记,我惊呆了
    查看>>
    Java程序员跳槽,三面之后被拒,原因竟是“招不起”
    查看>>
    想要彻底搞懂微服务架构?必先学:SpringBoot+SpringCloud+docker
    查看>>
    6天面试10家,已经拿到offer,Java程序员的面试总结分享
    查看>>
    渣本的逆袭之路!备战3个月,三面蚂蚁金服成功斩获Offer
    查看>>
    10月末美团、滴滴、蘑菇街9次面试总结(Java岗)
    查看>>
    热气腾腾的腾讯后台开发面经(总共五面)
    查看>>
    深入理解设计模式(设计原则+种设计模式+设计模式PK+设计模式混编)
    查看>>
    谷歌大佬回国发展,吊打各大厂面试官!吐血总结大厂面试高频点及笔记解析
    查看>>
    面试复盘:面完字节、美团、阿里等大厂,今年面试到底问什么?
    查看>>
    从0到1,决战Spring Boot《Spring Boot 2实战之旅》
    查看>>
    5面终于拿到字节跳动offer!忍不住和大家分享一波
    查看>>