Skip to content

Commit

Permalink
Create process-rel-links.js
Browse files Browse the repository at this point in the history
From https://github.com/CoryG89/docsync to get relative links working
  • Loading branch information
stevemoser committed Jan 25, 2015
1 parent 8483a60 commit 2ffc698
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions javascripts/process-rel-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* process-rel-links.js
* Author: Cory Gross
*
* This simple jQuery script is called once the DOM structure has been
* completely loaded. In order to make relative linking work correctly on
* the Jekyll based GitHub Pages: we take each anchor on which the inner
* anonymous function is executed, with the function context 'this' set to
* the anchor element on which the function is being called. The function
* simply determines if the extension is .md and removes it if so.
**/

$(function () {
$('a').each(function () {
var ext = '.md';
var href = $(this).attr('href');
var position = href.length - ext.length;
if (href.substring(position) === ext)
$(this).attr('href', href.substring(0, position));
});
});

0 comments on commit 2ffc698

Please sign in to comment.