这个问题可能有些令人困惑,所以让我澄清一下。
Github 可以让你查看存储库中文件的源代码。我想将它们包含在 iframe 中,但不确定如何操作,而且怀疑已经有人做过这个操作。
在我的情况下,我想将https://github.com/ileathan/hubot-mubot/blob/master/src/mubot.coffee 添加到一个 iframe 中,以便从我的网站上的人可以看到代码的演变。
这个问题可能有些令人困惑,所以让我澄清一下。
Github 可以让你查看存储库中文件的源代码。我想将它们包含在 iframe 中,但不确定如何操作,而且怀疑已经有人做过这个操作。
在我的情况下,我想将https://github.com/ileathan/hubot-mubot/blob/master/src/mubot.coffee 添加到一个 iframe 中,以便从我的网站上的人可以看到代码的演变。
iframe
中(因为有 X-Frame-Options: deny
HTTP 标头)。GET /repos/:owner/:repo/contents/:path
例如:{{link1:https://api.github.com/repos/ileathan/hubot-mubot/contents/src/mubot.coffee}}。
<iframe id="github-iframe" src=""></iframe>
<script>
fetch('https://api.github.com/repos/ileathan/hubot-mubot/contents/src/mubot.coffee')
.then(function(response) {
return response.json();
}).then(function(data) {
var iframe = document.getElementById('github-iframe');
iframe.src = 'data:text/html;base64,' + encodeURIComponent(data['content']);
});
</script>
以下是代码示例 https://jsfiddle.net/j8brpdsg/2/
<iframe frameborder=0 style="min-width: 200px; width: 60%; height: 460px;" scrolling="no" seamless="seamless" srcdoc='<html><body><style type="text/css">.gist .gist-data { height: 400px; }</style><script src="https://gist.github.com/sundbry/55bb902b66a39c0ff83629d9a8015ca4.js"></script></body></html>'></iframe>
这是我刚刚制作的一个测试,成功了! :)Usage
Take a github file url and prefix it with http://gist-it.appspot.com and embed the result within a tag:
<script src="http://gist-it.appspot.com/http://github.com/$file"></script>