Skip to content

Instantly share code, notes, and snippets.

@codenamev
Created September 6, 2012 14:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save codenamev/3656754 to your computer and use it in GitHub Desktop.
Save codenamev/3656754 to your computer and use it in GitHub Desktop.
Embed GitHub gist on your Tumblr
// REQUIRES:
// http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js
// http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js
// Based on: https://gist.github.com/1395926
$(document).ready(function() {
$('.gist').each(function(i) {
var file_separator = $(this).text().indexOf('#');
if (file_separator != -1) {
var gist_url = $(this).text().slice(0, file_separator);
var gist_file = $(this).text().slice(file_separator).replace("#file_", "?file=");
var gist_script_src = gist_url + '.js' + gist_file;
writeCapture.html(this, '<script src="'+gist_script_src+'"></script>');
} else {
writeCapture.html(this, '<script src="'+$(this).text()+'.js"></script>');
}
});
});
@codenamev
Copy link
Author

<!-- Add the following lines to theme's html code right before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="https://gist.github.com/raw/3656754/619d92a3b3153770cb350b113ac8d2c43fd2589f/gistfile1.js"></script>

<!--
  Usage: just add <div class="gist">[gist URL]</div>
  Example: <div class="gist">https://gist.github.com/1395926</div>
-->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment