-
-
Save joelpalmer/7adf0c9f667c21633388 to your computer and use it in GitHub Desktop.
Slugging
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 slug (text) { | |
var separator = /[^a-z0-9]+/ig; | |
var drop = /^-|-$/g; | |
return text | |
.replace(separator, '-') | |
.replace(drop, '') | |
.toLowerCase(); | |
} | |
function stamp(date){ | |
return slug(date.toDateString()); | |
} | |
var post = { | |
title: 'Dodgers are awesome', | |
date: new Date() | |
}; | |
var _slug = slug(post.title); | |
var time = stamp(post.date); | |
var url = '/' + time + '/' + _slug; | |
console.log(url); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment