Created
November 13, 2015 17:56
-
-
Save heytomsmith/05d7cefd59a27e1ff51d to your computer and use it in GitHub Desktop.
Create unique tumblr ID based on permalink slug
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 slugify() { | |
function removeBaseURL(url) { | |
return url.substring(url.lastIndexOf('/') + 1); | |
} | |
function convertToSlug(text) { | |
return text.toLowerCase() | |
.replace(/ /g, '-') | |
.replace(/[^\w-]+/g, ''); | |
} | |
$('article').each(function(i) { | |
var t = $(this).data('slug'); | |
t = removeBaseURL(t); | |
t = convertToSlug(t); | |
$(this).attr("id", t); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment