Skip to content

Instantly share code, notes, and snippets.

@artcommacode
Created February 8, 2013 19:48
Show Gist options
  • Save artcommacode/4741461 to your computer and use it in GitHub Desktop.
Save artcommacode/4741461 to your computer and use it in GitHub Desktop.
var hostname = url.parse(post.url).hostname;
if (hostname.indexOf('vimeo') != -1) {
var id = url.parse(post.url).pathname;
if (id) {
post.type = 'vimeo';
post.videoID = id;
} else {
post.type = 'link';
}
} else if (hostname.indexOf('youtu') != -1) {
var query = qs.parse(url.parse(post.url).query);
if (query.v) {
post.type = 'youtube';
post.videoID = query.v;
} else {
post.type = 'link';
}
} else if (post.url.match(/\.(jpeg|jpg|gif|png)$/) !== null) {
post.type = 'image';
} else {
post.type = 'link';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment