iframegithub

Is there a way to embed github code into an iframe?


The question may seem confusing so let me clarify.

Github lets you see the source code of a files in a repo. I want to include them in iframes but am unsure how and suspect someone has already done this before.

In my case I want to add https://github.com/ileathan/hubot-mubot/blob/master/src/mubot.coffee to an iframe so that from my website people can see the code as it evolves.


Solution

  • A GitHub page itself wouldn't be put directly in an iframe (because of the X-Frame-Options: deny HTTP header).

    That leaves you with the GitHub API for contents: "Use the REST API to create, modify, and delete Base64 encoded content in a repository"

    GET /repos/:owner/:repo/contents/:path
    

    Like: https://api.github.com/repos/ileathan/hubot-mubot/contents/src/mubot.coffee.

    You should be able to put that content in an iframe (as in this answer)