Skip to content

Instantly share code, notes, and snippets.

@captbaritone
Created May 9, 2015 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save captbaritone/99d9b9cdfa03523505df to your computer and use it in GitHub Desktop.
Save captbaritone/99d9b9cdfa03523505df to your computer and use it in GitHub Desktop.
<script src="js/marked.js"></script>
<script>
function render(data) {
if(data.template) {
var request = new XMLHttpRequest();
request.onload = function() {
delete data.template;
var front = /^---\n((.|\n)*)\n---/;
data.content = request.response.replace(front, function(f, json) {
settings = JSON.parse(json);
for(var i in settings){ data[i] = data[i] || settings[i]; }
return '';
}).replace(/{{ (.*) }}/g, function(match, wildcard) {
return data[wildcard] || match;
});
render(data);
};
request.open("get", data.template);
request.send();
} else {
document.body.innerHTML = marked(data.content);
}
}
onhashchange = function() {
template = location.hash.length ? location.hash.slice(1) : 'index';
render({'template': template + ".md"});
}
onhashchange();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment