diff --git a/README.md b/README.md index 439a729c..bf83948b 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,10 @@ Type `levels` to see the available lessons / challenges (and which ones you have For some added fun, there is a "git golf" concept where we keep track of how many commands you use to solve each level. See if you can match all of our records! +### Sharing permalinks + +You can share a link to LearnGitBranching with an arbitrary set of commands that will execute upon load by using the `commmand` URL parameter. You will also likely want to disable the intro dialog for this case with the `NODEMO` url param; here is [an example](https://learngitbranching.js.org/?NODEMO&command=echo%20%22hello%22;%20git%20commit) to get started. + ### Level Builder You can build levels with `build level`. The dialog will walk you through the process, and at the end you can `export level` to get a JSON blob. Paste that in a gist or directly into an issue and I can check it out / merge in your changes! You can also share this level directly with friends by having them run "import level" or simply specify a gist ID in the url params like so: diff --git a/src/js/dialogs/sandbox.js b/src/js/dialogs/sandbox.js index a121ab55..8ca35b90 100644 --- a/src/js/dialogs/sandbox.js +++ b/src/js/dialogs/sandbox.js @@ -14,6 +14,8 @@ exports.dialog = { 'beginner, just go ahead and start with the first. If you already know some Git basics, ', 'try some of our later more challenging levels.', '', + 'You can see all the commands available with `show commands` at the terminal.', + '', 'PS: Want to go straight to a sandbox next time?', 'Try out ', '[this special link](http://pcottle.github.io/learnGitBranching/?NODEMO)' diff --git a/src/js/sandbox/commands.js b/src/js/sandbox/commands.js index 06f33333..6da2b6a6 100644 --- a/src/js/sandbox/commands.js +++ b/src/js/sandbox/commands.js @@ -125,7 +125,8 @@ var regexMap = { 'importLevelNow': /^importLevelNow($|\s)/, 'import tree': /^import +tree$/, 'import level': /^import +level$/, - 'undo': /^undo($|\s)/ + 'undo': /^undo($|\s)/, + 'share permalink': /^share( +permalink)?$/ }; var getAllCommands = function() { diff --git a/src/js/sandbox/index.js b/src/js/sandbox/index.js index f6fd0c81..3d81ee9a 100644 --- a/src/js/sandbox/index.js +++ b/src/js/sandbox/index.js @@ -223,6 +223,16 @@ var Sandbox = Backbone.View.extend({ }); }, + sharePermalink: function(command, deferred) { + var treeJSON = JSON.stringify(this.mainVis.gitEngine.exportTree()); + var url = + 'https://learngitbranching.js.org/?NODEMO&command=importTreeNow%20' + escape(treeJSON); + command.setResult( + intl.todo('Here is a link to the current state of the tree: ') + url + ); + command.finishWith(deferred); + }, + resetSolved: function(command, deferred) { LevelActions.resetLevelsSolved(); command.addWarning( @@ -253,6 +263,7 @@ var Sandbox = Backbone.View.extend({ 'importTreeNow': this.importTreeNow, 'import level': this.importLevel, 'importLevelNow': this.importLevelNow, + 'share permalink': this.sharePermalink, }; var method = commandMap[command.get('method')];