Skip to content

Instantly share code, notes, and snippets.

@budparr
Last active April 12, 2016 05:50
Show Gist options
  • Save budparr/ddb02eea7512b77f7340fe5e6b9bf503 to your computer and use it in GitHub Desktop.
Save budparr/ddb02eea7512b77f7340fe5e6b9bf503 to your computer and use it in GitHub Desktop.
Convert a Jekyll site's front matter from a 13 digit ISBN, to a 10 digit ASIN and create a direct link to the book's page on Amazon.
<script type="text/javascript">
function ISBN13toISBN10(isbn13) {var start = isbn13.substring(3, 12);var sum = 0;var mul = 10;var i;for(i = 0; i < 9; i++) {sum = sum + (mul * parseInt(start[i]));mul -= 1;}var checkDig = 11 - (sum % 11);if (checkDig == 10) {checkDig = "X";} else if (checkDig == 11) {checkDig = "0";}return start + checkDig;}document.getElementById("isbn10_{{ isbn }}").innerHTML='<a href="http://www.amazon.com/dp/' + ISBN13toISBN10("{{ isbn }}") +'" title="Amazon" target="_blank" >Amazon</a>';
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment