Last active
December 25, 2015 15:25
-
-
Save idvorkin/9c5a4032f713b1c2ccd2 to your computer and use it in GitHub Desktop.
swap between github pages and local pretzel blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function swapLocalRemoteBlog() { | |
/* | |
* Pretzel renders, but doesn't navigate the same as github pages (GHP). | |
* Thus use GHP to navigate, then use this bookmarklet to swap with local pretzel blog. | |
*/ | |
var currentUrl = document.URL; | |
var errorMessage = "Only works on Igor's Blog"; | |
var githubBlogURL = "http://idvorkin.github.io"; | |
var localPretzelBlogUrl = "http://localhost:8080"; | |
var newUrl = ""; | |
if (currentUrl.startsWith(githubBlogURL)) { | |
newUrl = currentUrl.replace(githubBlogURL,localPretzelBlogUrl); | |
/*pretzel can't have a trailing slash - Issue 289, so remove it*/ | |
newUrl = newUrl.substr(0, newUrl.length-1) | |
} else if (currentUrl.startsWith(localPretzelBlogUrl)) { | |
newUrl = currentUrl.replace(localPretzelBlogUrl,githubBlogURL); | |
} else { | |
alert(errorMessage); | |
return; | |
} | |
window.location = newUrl; | |
}; | |
swapLocalRemoteBlog(); | |
void(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To convert to a bookmarklet - Join all lines into a single line and prepend the line with javascript: