rgrove / rawgit

Served files from raw.githubusercontent.com, but with the correct content types. No longer actively developed.

Home Page:https://rawgit.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Relative asset links don't work in gist URLs generated by the URL formatter

mcordingley opened this issue · comments

This could just be that it takes time for RawGit to index the files for all I know. If it is, then the request is instead to please add that to the FAQ.

I just pushed up https://rawgit.com/mcordingley/8244698fac2143f74b77fa15a68dd4bf/raw/4ac857dd601e3ad3785aa9676a15243a1f6ea5bd/index.html as a Gist and tried to view it over RawGit. However, the CSS and JS fail to load. The links all resolve back to the HTML file. The URLs are all good when I check the raw files on Gist, so it seems to be a translation issue.

Also, thanks for the service!

Interesting. The gist API is returning a raw URL for that file that contains a hash that doesn't seem to correspond to an actual commit within the gist repo. Requests using that hash, regardless of the filename, always return the contents of index.html.

However, when I use the "Raw" button on the gist to get the raw URL of index.html, that URL contains a valid commit hash, and RawGit transforms it into the following URL, which appears to work as expected:

https://rawgit.com/mcordingley/8244698fac2143f74b77fa15a68dd4bf/raw/058cc489317b92ac344a6458dcc80d70fb606217/index.html

Seems like I may need to use a different API endpoint to get a working commit hash that can be used to request other files in the gist.

GitHub API response
{
  "url": "https://api.github.com/gists/8244698fac2143f74b77fa15a68dd4bf",
  "forks_url": "https://api.github.com/gists/8244698fac2143f74b77fa15a68dd4bf/forks",
  "commits_url": "https://api.github.com/gists/8244698fac2143f74b77fa15a68dd4bf/commits",
  "id": "8244698fac2143f74b77fa15a68dd4bf",
  "git_pull_url": "https://gist.github.com/8244698fac2143f74b77fa15a68dd4bf.git",
  "git_push_url": "https://gist.github.com/8244698fac2143f74b77fa15a68dd4bf.git",
  "html_url": "https://gist.github.com/8244698fac2143f74b77fa15a68dd4bf",
  "files": {
    "index.html": {
      "filename": "index.html",
      "type": "text/html",
      "language": "HTML",
      "raw_url": "https://gist.githubusercontent.com/mcordingley/8244698fac2143f74b77fa15a68dd4bf/raw/4ac857dd601e3ad3785aa9676a15243a1f6ea5bd/index.html",
      "size": 3260,
      "truncated": false,
      "content": "<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\" />\n        <link rel=\"stylesheet\" href=\"./styles.css\" />\n    </head>\n    <body>\n        <div class=\"mx-auto max-width-4\">\n            <h1>Message Commitment</h1>\n\n            <p>\n                This is the digital equivalent of writing something down onto a slip of paper to reveal it later. Your\n                commitment is your slip of paper and the committed message is what you wrote inside. Just send the\n                commitment code to someone or post it on social media to lay down your slip of paper. Later, post the\n                reveal code to reveal what you had written down. With these two codes in hand, anyone may verify that\n                you revealed what you had committed to reveal.\n            </p>\n\n            <p>\n                Under the hood, the envelope is actually a\n                <a href=\"https://en.wikipedia.org/wiki/Cryptographic_hash_function\" target=\"_blank\">cryptographic hash</a>\n                of your message, padded out with some random data to ensure that your message cannot reasonably be\n                either guessed ahead of time or altered before being revealed. The calculations are done entirely\n                within your browser, so no one else is in possession of your message until its time comes.\n            </p>\n\n            <div class=\"clearfix mxn1\">\n                <div class=\"col col-12 md-col-6 px1\">\n                    <h2>Commit to a Message</h2>\n\n                    <label for=\"message\">Message</label>\n                    <textarea id=\"message\" class=\"block border-box col-12 mb2\" name=\"message\" rows=\"4\"></textarea>\n\n                    <label for=\"post_now\">Commitment (Post This Now)</label>\n                    <textarea id=\"post_now\" class=\"block border-box col-12 mb2\" name=\"post_now\" rows=\"4\" readonly></textarea>\n\n                    <label for=\"post_later\">Committed Message (Post This Later)</label>\n                    <textarea id=\"post_later\" class=\"block border-box col-12 mb2\" name=\"post_later\" rows=\"4\" readonly></textarea>\n\n                    <input type=\"button\" id=\"commit\" class=\"bg-white block blue border border-blue col-12 mb2 p1 pointer rounded\" value=\"Commit\" />\n                </div>\n\n                <div class=\"col col-12 md-col-6 px1\">\n                    <h2>Verify a Committed Message</h2>\n\n                    <label for=\"commitment\">Commitment</label>\n                    <textarea id=\"commitment\" class=\"block border-box col-12 mb2\" name=\"commitment\" rows=\"4\"></textarea>\n\n                    <label for=\"committed_message\">Committed Message</label>\n                    <textarea id=\"committed_message\" class=\"block border-box col-12 mb2\" name=\"committed_message\" rows=\"4\"></textarea>\n\n                    <input type=\"button\" id=\"verify\" class=\"bg-white block blue border border-blue col-12 mb2 p1 pointer rounded\" value=\"Verify\" />\n\n                    <p id=\"verification\" class=\"red\"></p>\n                </div>\n            </div>\n\n            <p class=\"text-muted\">Disclaimer: This has not been reviewed by a professional cryptographer. Use it at your own risk and for your own fun.</p>\n        </div>\n\n        <script src=\"./page.js\"></script>\n    </body>\n</html>"
    },
    "page.js": {
      "filename": "page.js",
      "type": "application/javascript",
      "language": "JavaScript",
      "raw_url": "https://gist.githubusercontent.com/mcordingley/8244698fac2143f74b77fa15a68dd4bf/raw/a2424c21de9e9c66d92a18c1f8ba40be89c541b5/page.js",
      "size": 2528,
      "truncated": false,
      "content": "(function () {\n    function sha256(str) {\n        return window.crypto.subtle.digest(\"SHA-256\", new TextEncoder(\"utf-8\").encode(str)).then(function (hash) {\n            return base64(hash);\n        });\n    }\n\n    function base64(buffer) {\n        var binary = '',\n            bytes = new Uint8Array(buffer),\n            len = bytes.byteLength;\n\n        for (var i = 0; i < len; i++) {\n            binary += String.fromCharCode(bytes[i]);\n        }\n\n        return window.btoa(binary);\n    }\n\n    document.getElementById('commit').addEventListener('click', function () {\n        var prefixBuffer = new Uint8Array(6),\n            suffixBuffer = new Uint8Array(33);\n\n        window.crypto.getRandomValues(prefixBuffer);\n        window.crypto.getRandomValues(suffixBuffer);\n\n        var message = document.getElementById('message').value.trim(),\n            prefix = base64(prefixBuffer),\n            suffix = base64(suffixBuffer),\n            post_later = prefix + '|' + message + '|' + suffix;\n\n        document.getElementById('post_later').value = post_later;\n\n        sha256(post_later).then(function (hash) {\n            document.getElementById('post_now').value = prefix + '|' + hash;\n        });\n    });\n\n    document.getElementById('verify').addEventListener('click', function () {\n        var commitment = document.getElementById('commitment').value.trim(),\n            commitmentPrefix = commitment.substring(0, commitment.indexOf('|')),\n            committedMessage = document.getElementById('committed_message').value.trim(),\n            prefix = committedMessage.substring(0, committedMessage.indexOf('|')),\n            suffix = committedMessage.substring(committedMessage.lastIndexOf('|') + 1);\n\n        if (commitmentPrefix !== prefix) {\n            document.getElementById('verification').innerText = 'Unable to verify committed message.';\n\n            return;\n        }\n\n        sha256(committedMessage).then(function (hash) {\n            var calculated = prefix + '|' + hash;\n\n            document.getElementById('verification').innerText = calculated === commitment ?\n                'Committed message verified.' :\n                'Unable to verify committed message.';\n        });\n    });\n\n    document.getElementById('commitment').addEventListener('input', function () {\n        document.getElementById('verification').innerText = '';\n    });\n\n    document.getElementById('committed_message').addEventListener('input', function () {\n        document.getElementById('verification').innerText = '';\n    });\n})();"
    },
    "styles.css": {
      "filename": "styles.css",
      "type": "text/css",
      "language": "CSS",
      "raw_url": "https://gist.githubusercontent.com/mcordingley/8244698fac2143f74b77fa15a68dd4bf/raw/0ca3b1228a031f4545a984ebd848999a7cbcc5db/styles.css",
      "size": 1451,
      "truncated": false,
      "content": "body {\n    background-color: #eee;\n    color: #212121;\n    font-family: \"Palatino Linotype\", Palatino, Palladio, \"URW Palladio L\", \"Book Antiqua\", Baskerville, \"Bookman Old Style\", \"Bitstream Charter\", \"Nimbus Roman No9 L\", Garamond, \"Apple Garamond\", \"ITC Garamond Narrow\", \"New Century Schoolbook\", \"Century Schoolbook\", \"Century Schoolbook L\", Georgia, serif;\n    font-size: 18px;\n}\n\nh1,\nh2,\na,\n.blue {\n    color: #008;\n}\n\na {\n    text-decoration: none;\n}\n\nh1,\nh2,\nlabel,\np {\n    text-shadow: 1px 1px 0 #fff;\n}\n\ninput,\ntextarea {\n    font-family: monospace;\n    font-size: 16px;\n}\n\n.block {\n    display: block;\n}\n\n.clearfix:before,\n.clearfix:after {\n  content: \" \";\n  display: table;\n}\n\n.clearfix:after {\n    clear: both;\n}\n\n.max-width-4 {\n    max-width: 64rem;\n}\n\n.border-box {\n    box-sizing: border-box;\n}\n\n.mb2 {\n    margin-bottom: 1rem;\n}\n\n.mxn1 {\n    margin-left: -.5rem;\n    margin-right: -.5rem;\n}\n\n.mx-auto {\n    margin-left: auto;\n    margin-right: auto;\n}\n\n.p1 {\n    padding: .5rem;\n}\n\n.px1 {\n    padding-left: .5rem;\n    padding-right: .5rem;\n}\n\n.col {\n  box-sizing: border-box;\n  float: left;\n}\n\n.col-12 {\n  width: 100%;\n}\n\n@media (min-width: 52em) {\n  .md-col-6 {\n    width: 50%;\n  }\n}\n\n.border {\n  border-style: solid;\n  border-width: 1px;\n}\n\n.rounded {\n    border-radius: 3px;\n}\n\n.bg-white {\n    background-color: #fff;\n}\n\n.border-blue {\n    border-color: #008;\n}\n\n.text-muted {\n    color: #888;\n}\n\n.pointer {\n    cursor: pointer;\n}"
    }
  },
  "public": true,
  "created_at": "2017-12-11T20:35:34Z",
  "updated_at": "2017-12-11T21:06:17Z",
  "description": "Message Commitment",
  "comments": 0,
  "user": null,
  "comments_url": "https://api.github.com/gists/8244698fac2143f74b77fa15a68dd4bf/comments",
  "owner": {
    "login": "mcordingley",
    "id": 1084253,
    "avatar_url": "https://avatars3.githubusercontent.com/u/1084253?v=4",
    "gravatar_id": "",
    "url": "https://api.github.com/users/mcordingley",
    "html_url": "https://github.com/mcordingley",
    "followers_url": "https://api.github.com/users/mcordingley/followers",
    "following_url": "https://api.github.com/users/mcordingley/following{/other_user}",
    "gists_url": "https://api.github.com/users/mcordingley/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/mcordingley/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/mcordingley/subscriptions",
    "organizations_url": "https://api.github.com/users/mcordingley/orgs",
    "repos_url": "https://api.github.com/users/mcordingley/repos",
    "events_url": "https://api.github.com/users/mcordingley/events{/privacy}",
    "received_events_url": "https://api.github.com/users/mcordingley/received_events",
    "type": "User",
    "site_admin": false
  },
  "forks": [

  ],
  "history": [
    {
      "user": {
        "login": "mcordingley",
        "id": 1084253,
        "avatar_url": "https://avatars3.githubusercontent.com/u/1084253?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/mcordingley",
        "html_url": "https://github.com/mcordingley",
        "followers_url": "https://api.github.com/users/mcordingley/followers",
        "following_url": "https://api.github.com/users/mcordingley/following{/other_user}",
        "gists_url": "https://api.github.com/users/mcordingley/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/mcordingley/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/mcordingley/subscriptions",
        "organizations_url": "https://api.github.com/users/mcordingley/orgs",
        "repos_url": "https://api.github.com/users/mcordingley/repos",
        "events_url": "https://api.github.com/users/mcordingley/events{/privacy}",
        "received_events_url": "https://api.github.com/users/mcordingley/received_events",
        "type": "User",
        "site_admin": false
      },
      "version": "058cc489317b92ac344a6458dcc80d70fb606217",
      "committed_at": "2017-12-11T21:06:17Z",
      "change_status": {
        "total": 4,
        "additions": 2,
        "deletions": 2
      },
      "url": "https://api.github.com/gists/8244698fac2143f74b77fa15a68dd4bf/058cc489317b92ac344a6458dcc80d70fb606217"
    },
    {
      "user": {
        "login": "mcordingley",
        "id": 1084253,
        "avatar_url": "https://avatars3.githubusercontent.com/u/1084253?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/mcordingley",
        "html_url": "https://github.com/mcordingley",
        "followers_url": "https://api.github.com/users/mcordingley/followers",
        "following_url": "https://api.github.com/users/mcordingley/following{/other_user}",
        "gists_url": "https://api.github.com/users/mcordingley/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/mcordingley/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/mcordingley/subscriptions",
        "organizations_url": "https://api.github.com/users/mcordingley/orgs",
        "repos_url": "https://api.github.com/users/mcordingley/repos",
        "events_url": "https://api.github.com/users/mcordingley/events{/privacy}",
        "received_events_url": "https://api.github.com/users/mcordingley/received_events",
        "type": "User",
        "site_admin": false
      },
      "version": "c2011981ddd5919a205b43098db0d5ed434c2a86",
      "committed_at": "2017-12-11T20:53:41Z",
      "change_status": {
        "total": 0,
        "additions": 0,
        "deletions": 0
      },
      "url": "https://api.github.com/gists/8244698fac2143f74b77fa15a68dd4bf/c2011981ddd5919a205b43098db0d5ed434c2a86"
    },
    {
      "user": {
        "login": "mcordingley",
        "id": 1084253,
        "avatar_url": "https://avatars3.githubusercontent.com/u/1084253?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/mcordingley",
        "html_url": "https://github.com/mcordingley",
        "followers_url": "https://api.github.com/users/mcordingley/followers",
        "following_url": "https://api.github.com/users/mcordingley/following{/other_user}",
        "gists_url": "https://api.github.com/users/mcordingley/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/mcordingley/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/mcordingley/subscriptions",
        "organizations_url": "https://api.github.com/users/mcordingley/orgs",
        "repos_url": "https://api.github.com/users/mcordingley/repos",
        "events_url": "https://api.github.com/users/mcordingley/events{/privacy}",
        "received_events_url": "https://api.github.com/users/mcordingley/received_events",
        "type": "User",
        "site_admin": false
      },
      "version": "acc189e59836217e6369db968d35962e4504465f",
      "committed_at": "2017-12-11T20:35:34Z",
      "change_status": {
        "total": 246,
        "additions": 246,
        "deletions": 0
      },
      "url": "https://api.github.com/gists/8244698fac2143f74b77fa15a68dd4bf/acc189e59836217e6369db968d35962e4504465f"
    }
  ],
  "truncated": false
}

That sounds almost like a bug in the Gist API, then.

This has been idle for over a year. Closing.

You might want to read the news on https://rawgit.com/.

Makes sense. 👍