Skip to content

Instantly share code, notes, and snippets.

@yssk22
Created August 22, 2010 07:54
Show Gist options
  • Save yssk22/543508 to your computer and use it in GitHub Desktop.
Save yssk22/543508 to your computer and use it in GitHub Desktop.
function(doc){
if( doc.type != "twitter" || doc.source == undefined ){
return;
}
if( doc.source.text ){
function hyperlink(text){
return text.replace(/(https?:\/\/[^\s]+)/g, '<a class="hyperlink" href="$1" target="_new">$1</a>');
}
function mentionlink(text){
return text.replace(/@([a-zA-Z_0-9]+)/g, '<a class="mentionlink" href="http://twitter.com/$1">@$1</a>');
}
function hashtaglink(text){
return text.replace(/#([a-zA-Z_0-9]+)/g, '<a class="hashtaglink" href="http://twitter.com/search?q=%23$1">#$1</a>');
}
doc.hashtags = doc.source.text.match(/#([a-zA-Z_0-9]+)/g);
doc.mentions = doc.source.text.match(/@([a-zA-Z_0-9]+)/g);
doc.links = doc.source.text.match(/(https?:\/\/[^\s]+)/g);
// tweet
var t = Date.parse(doc.source.created_at);
doc.source.text = hashtaglink(mentionlink(hyperlink(doc.source.text)));
emit(['_', t], doc);
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment