Skip to content

Commit

Permalink
twitter stupidly "shortens" find.com into http://t.co/u44JiITiuc, cope
Browse files Browse the repository at this point in the history
try to pluck out simple urls in basic tlds and treat their length as
a t.co url if it's longer than the url being shortened

of course this will not catch all urls, but i'm not going to load a
whole suffix list or library just to deal with this stupid shit
  • Loading branch information
jcs committed Apr 17, 2015
1 parent 8f8ad57 commit b4444c5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions script/post_to_twitter
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ Time.now - 1.days).order(:id).each_with_index do |s,x|
title = "- #{title}"
end

# if there are any urls in the title, they should be sized (at least) to a
# twitter t.co url
left_len -= (title.scan(/[^ ]\.(com|org|net|edu)/i).map{|u| [ 0,
Twitter::TCO_LEN ].max }.inject(:+)).to_i

if title.bytesize > left_len
status = title[0, left_len - 3] + "..." + status
else
Expand Down

0 comments on commit b4444c5

Please sign in to comment.