javascript - 我可以直接從 GitHub 運行 HTML 文件,而不只是查看它們的源代碼嗎?
如果我在 GitHub 倉庫中有一個 .html 文件,例如用於運行一組 JavaScript 測試,有沒有辦法我可以直接查看該頁面——從而運行這些測試?
例如,我是否能以某種方式實際看到 jQuery 測試套件所產生的測試結果,而不需要將倉庫下載或克隆到我的本地硬碟並在那裡運行它們?
我知道這基本上會讓 GitHub 進入靜態內容託管業務,但另一方面,他們只需要將 mime-type 從 text/plain 改為 text/html 就行了。
答案#1
你可能想使用 raw.githack.com。它支援 GitHub、Bitbucket、Gitlab 和 GitHub gists。
GitHub
之前:
https://raw.githubusercontent.com/[user]/[repository]/[branch]/[filename.ext]在你的情況下,.html 擴展名
之後:
開發(受限)
https://raw.githack.com/[user]/[repository]/[branch]/[filename.ext]生產 (CDN)
https://rawcdn.githack.com/[user]/[repository]/[branch]/[filename.ext]在你的情況下,.html 擴展名
raw.githack.com 也支援其他服務:
Bitbucket
之前:
https://bitbucket.org/[user]/[repository]/raw/[branch]/[filename.ext]之後:
開發(受限)
https://bb.githack.com/[user]/[repository]/raw/[branch]/[filename.ext]生產 (CDN)
https://bbcdn.githack.com/[user]/[repository]/raw/[branch]/[filename.ext]GitLab
之前:
https://gitlab.com/[user]/[repository]/raw/[branch]/[filename.ext]之後:
開發(受限)
https://gl.githack.com/[user]/[repository]/raw/[branch]/[filename.ext]生產 (CDN)
https://glcdn.githack.com/[user]/[repository]/raw/[branch]/[filename.ext]GitHub 代碼片段
之前:
https://gist.githubusercontent.com/[user]/[gist]/raw/[revision]/[filename.ext]之後:
開發(受限)
https://gist.githack.com/[user]/[gist]/raw/[revision]/[filename.ext]生產 (CDN)
https://gistcdn.githack.com/[user]/[gist]/raw/[revision]/[filename.ext]更新:rawgit 已停止服務
答案#2
有一個名為 GitHub HTML Preview 的新工具,它完全可以做到你想要的功能。只需在任何 HTML 文件的 URL 前加上 http://htmlpreview.github.io/?,例如 http://htmlpreview.github.io/?https://github.com/twbs/bootstrap/blob/gh-pages/2.3.2/index.html
注意:此工具實際上是一個 github.io 頁面,並非與 github 公司相關聯。
答案#3
為了接續 @niutech 的回答,你可以做一個非常簡單的書籤小程式。
使用 Chrome,雖然在其他瀏覽器上也有類似的效果
- 在你的書籤列上點擊右鍵
- 點擊 新增檔案
- 給它取個像 Github HTML 這樣的名字
- 對於 URL 輸入
javascript:top.location="http://htmlpreview.github.com/?"+document.URL - 當你在 GitHub 文件檢視頁面(不是 raw.github.com)時,點擊書籤連結,你就完成了。