如何将 Github 上的 HTML 页面视为正常渲染的 HTML 页面,以便在浏览器中查看预览,而无需下载?
在 http://github.com 上,开发人员保留项目的 HTML、CSS、JavaScript 和图像文件。如何在浏览器中查看 HTML 输出?
例如: https://github.com/necolas /css3-social-signin-buttons/blob/master/index.html
当我打开它时,它不显示作者代码的渲染 HTML。它将页面显示为源代码。
是否可以直接将其视为呈现的 HTML?否则我总是需要下载整个 ZIP 才能看到结果。
On http://github.com developer keep the HTML, CSS, JavaScript and images files of the project. How can I see the HTML output in browser?
For example this: https://github.com/necolas/css3-social-signin-buttons/blob/master/index.html
When I open this it doesn't show the rendered HTML of the code of author. It shows the page as a source code.
Is it possible to see it as rendered HTML directly? Otherwise I always need to download the whole ZIP just to see the result.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
如果您使用的是企业 Github,您可能不希望拥有面向公众的 github 页面。对我们有用的一件事是:
对于 HTML 文件: https://github.private-repo.com/team/project/blob/master/order.html
以下是在浏览器中打开并以 HTML 形式检索最新文件的 URL:
https://github.private-repo.com/pages/team/项目/order.html
If you are using an enterprise Github, you might not want to have a public facing github pages. One thing that worked for us is to:
For a HTML file in: https://github.private-repo.com/team/project/blob/master/order.html
Following is the URL that opens in a browser and retrieves the latest file as HTML:
https://github.private-repo.com/pages/team/project/order.html
这不是一个直接的答案,但我认为这是一个非常不错的选择。
http://www.s3auth.com/
它允许您在基本身份验证后面托管您的页面。非常适合您的私人 github 存储库中的 api 文档之类的内容。只需将 s3 添加为 api 构建的一部分即可。
This isn't a direct answer, but I think it is a pretty sweet alternative.
http://www.s3auth.com/
It allows you to host your pages behind basic auth. Great for things like api docs in your private github repo. just ad a s3 put as part of your api build.
这是一个书签,用于将当前页面的内容替换为 HTML 文件的内容:
与使用 SingleFile 生成的自包含/零依赖 HTML 文件配合得很好,因为文件不这样做没有外部依赖项(例如,图像经过 Base64 编码并嵌入到 HTML 文件中)。
注意:
保留页面页眉和页脚的替代小书签代码,以便运行小书签不会破坏客户端路由:
github.com 上的 CSP 阻止 iframe 加载大多数链接,因此在此版本中,大多数链接都被有效禁用(即单击链接不会执行任何操作,至少在 Firefox 上)。就我而言,这是一个功能,而不是一个错误。
Here's a bookmarklet to replace the current page's contents with the HTML file's contents:
Works great with self-contained / zero-dependency HTML files generated with SingleFile as the files don't have external dependencies (e.g. images are base64-encoded and embedded in the HTML file).
Notes:
Alternative bookmarklet code that retains the page's header and footer, so that running the bookmarklet doesn't break client-side routing:
The CSP on github.com blocks the iframe from loading most links, so with this version most links are effectively disabled (i.e. clicking a link doesn't do anything, at least on Firefox). In my case this is a feature, not a bug.
因为旧项目被放弃而新分叉;
URL 现在为 (
htmlpreview
->html-preview
):< em>以前:
在 GitHub 上预览 HTML 文件的最舒适方法是访问 https: //htmlpreview.github.io/ 或者只是将其添加到原始 URL 之前,即: https://htmlpreview.github.io/?https://github.com/bartaz/impress.js/blob/master/index.html
New fork because the old project is abandoned;
The URLs are now (
htmlpreview
->html-preview
):previously:
The most comfortable way to preview HTML files on GitHub is to go to https://htmlpreview.github.io/ or just prepend it to the original URL, i.e.: https://htmlpreview.github.io/?https://github.com/bartaz/impress.js/blob/master/index.html
我阅读了所有评论,并认为 GitHub 让普通用户很难创建 GitHub 页面,直到我访问 GitHub 主题页面 其中明确提到设置页面下有一个“GitHub Pages”部分相关的仓库在哪里您可以选择“使用 GitHub Pages 的主分支”选项。瞧!!...在 https://username.github.io/reponame 上查看该特定存储库
I read all the comments and thought that GitHub made it too difficult for normal user to create GitHub pages until I visited GitHub theme Page where its clearly mentioned that there is a section of "GitHub Pages" under settings Page of the concerned repo where you can choose the option "use the master branch for GitHub Pages." and voilà!!...checkout that particular repo on https://username.github.io/reponame
如果您不想下载存档,可以使用 GitHub Pages 来呈现它。
gh-pages
分支(如果已经存在,请将其删除并基于master
创建一个新分支)。http://
用户名
.github.io/
repo< /code>
`
在代码中:
If you don't want to download an archive you can use GitHub Pages to render this.
gh-pages
branch (if one already exists, remove it and create a new one based offmaster
).http://
username
.github.io/
repo
`In code:
You can use RawGit:
https://rawgit.com/necolas/css3-social-signin-buttons/master/index.html
It works better (at the time of this writing) than http://htmlpreview.github.com/, serving files with proper Content-Type headers.
Additionally, it also provides CDN URL for use in production.
使用 github 页面 确实很容易做到,只是第一次做的时候有点奇怪。有点像你第一次在学习编织的同时不得不照顾三只小猫。 (好吧,这并不是那么糟糕)
你需要一个 gh-pages 分支:
基本上 github.com 会寻找存储库的 gh-pages 分支。它将在这里找到的所有 HTML 页面作为普通 HTML 直接提供给浏览器。
我如何获得这个 gh-pages 分支?
简单。只需创建一个名为 gh-pages 的 github 存储库分支即可。
创建此分支时指定
--orphan
,因为您实际上并不希望将此分支合并回 github 分支,您只需要一个包含 HTML 的分支资源。我的存储库中的所有其他垃圾怎么样?它们如何融入其中?
不,你可以继续删除它。现在这样做是安全的,因为您一直在关注并创建了一个孤立分支,该分支无法合并回主分支并删除所有代码。
我已经创建了分支,现在怎么办?
您需要将此分支推送到 github.com,以便他们的自动化可以启动并开始为您托管这些页面。
但是..我的 HTML 仍然没有被提供!
github 需要几分钟的时间来索引这些分支并启动所需的基础设施来提供内容。根据 github 最多 10 分钟。
github.com 列出的步骤
https:// help.github.com/articles/creating-project-pages-manually
It's really easy to do with github pages, it's just a bit weird the first time you do it. Sorta like the first time you had to juggle 3 kittens while learning to knit. (OK, it's not all that bad)
You need a gh-pages branch:
Basically github.com looks for a gh-pages branch of the repository. It will serve all HTML pages it finds in here as normal HTML directly to the browser.
How do I get this gh-pages branch?
Easy. Just create a branch of your github repo called
gh-pages
.Specify
--orphan
when you create this branch, as you don't actually want to merge this branch back into your github branch, you just want a branch that contains your HTML resources.What about all the other gunk in my repo, how does that fit in to it?
Nah, you can just go ahead and delete it. And it's safe to do now, because you've been paying attention and created an orphan branch which can't be merged back into your main branch and remove all your code.
I've created the branch, now what?
You need to push this branch up to github.com, so that their automation can kick in and start hosting these pages for you.
But.. My HTML is still not being served!
It takes a few minutes for github to index these branches and fire up the required infrastructure to serve up the content. Up to 10 minutes according to github.
The steps layed out by github.com
https://help.github.com/articles/creating-project-pages-manually
我找到了另一种方法:
在 Firefox 上测试,但也应该在其他浏览器中工作
I have found another way:
Tested on Firefox but it should work in other browsers too
两种方法(对于公共存储库)对我来说效果很好:非常简单,并且能够渲染复杂的 HTML 页面,并链接到本地 CSS 文件和本地 JAVASCRIPT/VUE 文件。
要进行设置,请转至:https:/ /github.com/YOUR_ACCT_NAME/YOUR_REPO_NAME/settings/pages(参见下面的屏幕截图)
存储库中我的原始 HTML 页面示例:https://github.com/BrainAnnex/life123/blob/main /experiments/life_1D/diffusion/diffusion_1.htm
渲染效果:https://brainannex.github.io/life123/experiments/life_1D/diffusion/diffusion_1 .htm 注意所有的样式、图形和交互控件都很好:)
转到https://raw.githack.com/并输入您页面的完整 URL(包括“/blob”部分);例如 https://github.com/BrainAnnex/life123/ blob/main/experiments/life_1D/diffusion/diffusion_1.htm
然后该网站会生成 2 个运行良好的链接:)
如果 GitHub 页面不可用,这是一个不错的选择!
Two approaches (for public repositories) worked well for me: both VERY SIMPLE and ABLE TO RENDER COMPLEX HTML PAGES with links to local CSS files and local JAVASCRIPT/VUE files.
To set up, go to: https://github.com/YOUR_ACCT_NAME/YOUR_REPO_NAME/settings/pages (see screen shot below)
Example of my original HTML page on the repo: https://github.com/BrainAnnex/life123/blob/main/experiments/life_1D/diffusion/diffusion_1.htm
How it looks rendered: https://brainannex.github.io/life123/experiments/life_1D/diffusion/diffusion_1.htm Notice how all the styling, graphics and interactive controls are all good :)
Go to https://raw.githack.com/ and enter the full URL of yourpage (including the "/blob" part); e.g. https://github.com/BrainAnnex/life123/blob/main/experiments/life_1D/diffusion/diffusion_1.htm
Then the site generates 2 links that work quite well :)
A good alternative if GitHub pages were to become unavailable!
另外,如果您使用 Tampermonkey,您可以添加一个脚本,将
preview with http://htmlpreview.github.com/
按钮添加到“raw”、“blame”和“history”旁边的操作菜单中按钮。像这样的脚本:
https://gist.github.com/vanyakosmos/83ba165b288af32cf85e2cac8f02ce6d
Also, if you use Tampermonkey, you can add a script that will add
preview with http://htmlpreview.github.com/
button into actions menu beside 'raw', 'blame' and 'history' buttons.Script like this one:
https://gist.github.com/vanyakosmos/83ba165b288af32cf85e2cac8f02ce6d
如果您配置了 GitHub Pages,您可以获得公共 URL,如下所示:
where
&
将是用户名和名称的占位符分别是 repo 名称所以,结果将是这样的:
http://necolas.github.io/css3-social-signin- Buttons/index.html
如果它是一个在所有存储库中启用了 GithubPages 的组织,它将类似于:
If you have configured GitHub Pages you can get your public url like as:
where
<username>
&<repository>
will be the placeholder for username & repo name respectivelySo, the result will be like this:
http://necolas.github.io/css3-social-signin-buttons/index.html
If it is an organization with GithubPages enabled in all the repositories it will be something like: