-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Share Sandcastle code using URL instead of gists. #6342
Conversation
Anonymous gist creation will be removed - #6232 Instead of publishing gists, when we share we now encode the code into the URL fragment, in compressed Base64 encoded form. (see code comments for the exact format) Existing gists still load as before.
Updated links now that the build has deployed: |
Our largest existing Sandcastle example loads correctly from a URL in Chrome and Firefox. Edge not so much - it seems to truncate the hash at around 2000 characters of original text. I won't paste the URL here because it's 28KB. For extreme sharing, you can still create gists manually under your own account as long as they exactly match the expected format: two files in the gist, named exactly |
) { | ||
'use strict'; | ||
|
||
// attach clipboard handling to our Copy button | ||
var clipboardjs = new ClipboardJS('.copyButton'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that Sandcastle uses an ancient version of Dojo probably doesn't help. @emackey you are probably the only one that actually knows dojo well enough to improve this. Feel free to open a PR into master if you want to take a stab at fixing it.
One day we'll get to rewrite Sandcastle.
This cleanup was long overdue, I'm sure @emackey will be very happy to see it as I know the HelloWorld thing irked him. Functionality all works as promised, does anyone else want to review this? |
Not sure what I as thinking when I used a query param instead of hash for this (though it's probably because I lazily copied/pasted the gist code. |
Well from recent experience, if you had tried to use the hash you would have immediately ran into all the problems I had to fix to make it work. |
Like I said, lazy 😄 |
Would it be possible to save the html code too? I liked how we did that with gists. But maybe it's better to save space on the fragment length. |
It does save both the JS and HTML tab contents. |
Oh hm.. maybe I am doing something wrong? When I open the new link the html is the original html. |
Actually, it's supposed to be but it seems like it's not working. Pretty sure it saves the contents but it isn't loading them. I'll debug it. |
Nice catch @lilleyse, thanks. |
Random though, should we also update the browser url when you hit share? This way that url actually works? Hell, we could just update it as you type (or on a timer) so that hitting F5 keeps your code. |
The code path for loading a demo from the gallery was still being run after we loaded from the URL, clobbering the URL data. The gist codepath only worked because the jsonp request made it so the gallery demo load was then overwritten by the correct data. Now we only parse and load from the demo if we actually need it.
The HTML loading should be fixed. There was still some remaining Sandcastle Insanity left - the code to load from the gallery always ran after loading from gist, for no reason. It only worked for gists because the JSONP load happened async so the correct content from gist clobbered the gallery content. Loading from the URL is sync so it loaded from there then immediately clobbered it with the gallery content. (also @mramato's query string code had the same bug for the same reason) |
Here's a gist with custom HTML: and the same content in the URL: |
I realized this is a bad idea since Edge/IE have issues with very long urls. |
Deployed! |
Anonymous gist creation will be removed - #6232
Instead of publishing gists, when we share we now encode the code into
the URL fragment, in compressed Base64 encoded form. (see code comments
for the exact format)
Existing gists still load as before.
I also tried to fix some of the existing "Sandcastle Insanity" in the code, such as making
src
andlabel
parameters truly optional (previously we desperately hardcodedsrc=Hello%20World.html&label=Showcases
all over the place when building URLs), and copying thegist
parameter togistId
because different sections of the code couldn't agree on what the variable name should be called.Example URLs:
loading existing gists:
http://localhost:8080/Apps/Sandcastle/?gist=661c0a1fc177d1cc07fdd30c9be1f971
@mramato 's previous code query param still works:
http://localhost:8080/Apps/Sandcastle/?code=eyJjb2RlIjoiLy9JIHdhcyBhIHF1ZXJ5IHBhcmFtISFcbnZhciB2aWV3ZXIgPSBuZXcgQ2VzaXVtLlZpZXdlcignY2VzaXVtQ29udGFpbmVyJyk7IiwiaHRtbCI6IjxzdHlsZT5cbkBpbXBvcnQgdXJsKC4uL3RlbXBsYXRlcy9idWNrZXQuY3NzKTtcbjwvc3R5bGU+XG48ZGl2IGlkPVwiY2VzaXVtQ29udGFpbmVyXCIgY2xhc3M9XCJmdWxsU2l6ZVwiPjwvZGl2PlxuPGRpdiBpZD1cImxvYWRpbmdPdmVybGF5XCI+PGgxPkxvYWRpbmcuLi48L2gxPjwvZGl2PlxuPGRpdiBpZD1cInRvb2xiYXJcIj48L2Rpdj5cbiJ9
New format using fragment/hash:
http://localhost:8080/Apps/Sandcastle/#c=ZY/NCgIxDIRfJfSigrR4ti6CV0FQ9NRL7Ua3mG2l6a7o01sVwZ/cZjLfwCgFLoaMITNQtDXWcEixhe16CY3lxoTeJug9XjDBDAJeYIHsu1bunt5w4J5yUUqsD5gGo6kYC835SliZAOXmvj3HlKFLNJRSZWzPZDOy2nfuhFk65tHUBK3ekK59D76eGfFTbgQ4sszlc+iINv6GRlRalfwX9ljiw3HVYyJ7fUSaSbV8mVJKrYr8p3KMtLfpo/EO
fixes #6232