Improved Dropbox sync

:  ~ 1 min read

I don't think this is a likely scenario, but I wanted to cover the case where two posts have the same title, and, most likely, the same URL. Filenames will always be unique, because their format is YYYY-MM-DD-Post title, meaning I can make use of this, when running the sync command:

# link is a formatted version of the Post title part
# datetime is the YYYY-MM-DD part
# If the datetime isn't the same, then it's just another post with the same name
while post && post.link == link && post.datetime != datetime
  if post.link[-3, 2] == '--'
    i = post.link[-1, 1].to_i
    link.sub!("--#{i}", "--#{i + 1}")
  # I know, I know, but I will never have so many duplicates
  elsif post.link[-4, 2] == '--' 
    i = post.link[-2, 2].to_i
    link.sub!("--#{i}", "--#{i + 1}")
  else
    link = "#{link}--#{1}"
  end
  
  # If it's nil, we will create a new one, which will have a --i suffix in the link
  post = Posts.first(:link => link) 
end