Skip to content

Instantly share code, notes, and snippets.

@heytomsmith
Created November 13, 2015 17:56
Show Gist options
  • Save heytomsmith/05d7cefd59a27e1ff51d to your computer and use it in GitHub Desktop.
Save heytomsmith/05d7cefd59a27e1ff51d to your computer and use it in GitHub Desktop.
Create unique tumblr ID based on permalink slug
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