如何将 Github 上的 HTML 页面视为正常渲染的 HTML 页面,以便在浏览器中查看预览,而无需下载?

发布于 2024-12-20 12:50:15 字数 425 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

夜声 2024-12-27 12:50:16

如果您使用的是企业 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

清引 2024-12-27 12:50:16

这不是一个直接的答案,但我认为这是一个非常不错的选择。

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.

情感失落者 2024-12-27 12:50:16

这是一个书签,用于将当前页面的内容替换为 HTML 文件的内容:

  1. 使用此“URL”创建书签:
    javascript: (() => {
       const 选择器 = '#read-only-cursor-text-area';
       const html = document.querySelector(selector)?.value;
    
       如果(!html){
         returnalert(`错误:未找到元素 ${selector}`);
      }
    
      文档.open();
      文档.write(html);
      文档.关闭();
    })();
    
  2. 在 GitHub 上打开 HTML 文件。
  3. 通过“打开”书签来运行书签。

与使用 SingleFile 生成的自包含/零依赖 HTML 文件配合得很好,因为文件不这样做没有外部依赖项(例如,图像经过 Base64 编码并嵌入到 HTML 文件中)。

注意:


保留页面页眉和页脚的替代小书签代码,以便运行小书签不会破坏客户端路由:

javascript: (() => {
  const selector = '#read-only-cursor-text-area';
  const html = document.querySelector(selector)?.value;

  if (!html) {
    return alert(`Error: element ${selector} not found`);
  }

  const $iframe = document.createElement('iframe');
  $iframe.style.height = '100vh';
  $iframe.style.width = '100%';
  $iframe.srcdoc = html;

  document.querySelector('turbo-frame').replaceChildren($iframe);

  $iframe.scrollIntoView();
})();

github.com 上的 CSP 阻止 iframe 加载大多数链接,因此在此版本中,大多数链接都被有效禁用(即单击链接不会执行任何操作,至少在 Firefox 上)。就我而言,这是一个功能,而不是一个错误。

Here's a bookmarklet to replace the current page's contents with the HTML file's contents:

  1. Create a bookmark with this "URL":
    javascript: (() => {
       const selector = '#read-only-cursor-text-area';
       const html = document.querySelector(selector)?.value;
    
       if (!html) {
         return alert(`Error: element ${selector} not found`);
      }
    
      document.open();
      document.write(html);
      document.close();
    })();
    
  2. Open an HTML file on GitHub.
  3. Run the bookmarklet by "opening" the bookmark.

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:

  • The bookmarklet breaks GitHub's client-side routing, so navigating back with the browser's Back button doesn't work. Reloading the page (F5) fixes the issue.
  • The bookmarklet doesn't work on raw.githubusercontent.com because of a strict Content Security Policy (CSP). (Plus the bookmarklet is looking for an element that's not present on this domain.)
  • The CSP used on github.com can also be too strict; in such cases, I would personally try an alternative solution posted by ostrokach to a similar question.
  • The bookmarklet is brittle, i.e. it might need tweaking from time to time as GitHub gets updated.

Alternative bookmarklet code that retains the page's header and footer, so that running the bookmarklet doesn't break client-side routing:

javascript: (() => {
  const selector = '#read-only-cursor-text-area';
  const html = document.querySelector(selector)?.value;

  if (!html) {
    return alert(`Error: element ${selector} not found`);
  }

  const $iframe = document.createElement('iframe');
  $iframe.style.height = '100vh';
  $iframe.style.width = '100%';
  $iframe.srcdoc = html;

  document.querySelector('turbo-frame').replaceChildren($iframe);

  $iframe.scrollIntoView();
})();

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.

江心雾 2024-12-27 12:50:15

因为旧项目被放弃而新分叉;
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

指尖微凉心微凉 2024-12-27 12:50:15

我阅读了所有评论,并认为 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

screenshot to support my answer

蝶…霜飞 2024-12-27 12:50:15

如果您不想下载存档,可以使用 GitHub Pages 来呈现它。

  1. 将存储库分叉到您的帐户。
  2. 在您的计算机上将其本地克隆
  3. 创建一个 gh-pages 分支(如果已经存在,请将其删除并基于 master 创建一个新分支)。
  4. 将分支推回 GitHub。
  5. 查看页面 http://用户名.github.io/repo< /code>`

在代码中:

git clone [email protected]:username/repo.git
cd repo
git branch gh-pages
# Might need to do this first: git branch -D gh-pages
git push -u origin gh-pages # Push the new branch back to github
Go to http://username.github.io/repo

If you don't want to download an archive you can use GitHub Pages to render this.

  1. Fork the repository to your account.
  2. Clone it locally on your machine
  3. Create a gh-pages branch (if one already exists, remove it and create a new one based off master).
  4. Push the branch back to GitHub.
  5. View the pages at http://username.github.io/repo`

In code:

git clone [email protected]:username/repo.git
cd repo
git branch gh-pages
# Might need to do this first: git branch -D gh-pages
git push -u origin gh-pages # Push the new branch back to github
Go to http://username.github.io/repo
溺渁∝ 2024-12-27 12:50:15

???? Message from RawGit's creator and owner on https://rawgit.com:

RawGit has reached the end of its useful life
October 8, 2018
RawGit is now in a sunset phase and will soon shut down. It's been a fun five years, but all things must end.

GitHub repositories that served content through RawGit within the last month will continue to be served until at least October of 2019. URLs for other repositories are no longer being served.

If you're currently using RawGit, please stop using it as soon as you can.

When I tried to use it, I got:

403 Forbidden

RawGit will soon shut down and is no longer serving new repos. >> Please visit https://rawgit.com for more details.

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.

我乃一代侩神 2024-12-27 12:50:15

使用 github 页面 确实很容易做到,只是第一次做的时候有点奇怪。有点像你第一次在学习编织的同时不得不照顾三只小猫。 (好吧,这并不是那么糟糕)

你需要一个 gh-pages 分支:

基本上 github.com 会寻找存储库的 gh-pages 分支。它将在这里找到的所有 HTML 页面作为普通 HTML 直接提供给浏览器。

我如何获得这个 gh-pages 分支?

简单。只需创建一个名为 gh-pages 的 github 存储库分支即可。
创建此分支时指定 --orphan ,因为您实际上并不希望将此分支合并回 github 分支,您只需要一个包含 HTML 的分支资源。

$ git checkout --orphan gh-pages

我的存储库中的所有其他垃圾怎么样?它们如何融入其中?

不,你可以继续删除它。现在这样做是安全的,因为您一直在关注并创建了一个孤立分支,该分支无法合并回主分支并删除所有代码。

我已经创建了分支,现在怎么办?

您需要将此分支推送到 github.com,以便他们的自动化可以启动并开始为您托管这些页面。

git push -u origin gh-pages

但是..我的 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.

$ git checkout --orphan gh-pages

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.

git push -u origin gh-pages

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

傲鸠 2024-12-27 12:50:15

我找到了另一种方法:

  1. 如果您还没有,请单击“Raw”按钮
  2. Ctrl+A、Ctrl+C
  3. 使用 F12 打开“开发人员工具”
  4. 在“检查器”中右键单击标签并选择“编辑 HTML”
  5. Ctrl+A、Ctrl+V
  6. Ctr+Return

在 Firefox 上测试,但也应该在其他浏览器中工作

I have found another way:

  1. Click on the "Raw" button if you haven't already
  2. Ctrl+A, Ctrl+C
  3. Open "Developer Tools" with F12
  4. In the "Inspector" right-click on the tag and choose "Edit HTML"
  5. Ctrl+A, Ctrl+V
  6. Ctr+Return

Tested on Firefox but it should work in other browsers too

乱了心跳 2024-12-27 12:50:15

两种方法(对于公共存储库)对我来说效果很好:非常简单,并且能够渲染复杂的 HTML 页面,并链接到本地​​ CSS 文件和本地 JAVASCRIPT/VUE 文件。

  • 方法 1 - 使用 GitHub 页面

要进行设置,请转至: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 注意所有的样式、图形和交互控件都很好:)

  • 方法 2 - 免费服务raw.githack.com

转到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.

  • METHOD 1 - With GitHub pages

To set up, go to: https://github.com/YOUR_ACCT_NAME/YOUR_REPO_NAME/settings/pages (see screen shot below)

enter image description here

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 :)

  • METHOD 2 - With free service raw.githack.com

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!

伴我心暖 2024-12-27 12:50:15

另外,如果您使用 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

忆梦 2024-12-27 12:50:15

如果您配置了 GitHub Pages,您可以获得公共 URL,如下所示:

https://<username>.github.io/<repository>/index.html

where & 将是用户名和名称的占位符分别是 repo 名称

所以,结果将是这样的:
http://necolas.github.io/css3-social-signin- Buttons/index.html

如果它是一个在所有存储库中启用了 GithubPages 的组织,它将类似于:

https://<org>.github.io/<repository>/

If you have configured GitHub Pages you can get your public url like as:

https://<username>.github.io/<repository>/index.html

where <username> & <repository> will be the placeholder for username & repo name respectively

So, 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:

https://<org>.github.io/<repository>/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文