May 04, 2015:  ~ 2 min read

Improved Dropbox sync

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 && == link && post.datetime != datetime
  if[-3, 2] == '--'
    i =[-1, 1].to_i
    link.sub!("--#{i}", "--#{i + 1}")
  # I know, I know, but I will never have so many duplicates
  elsif[-4, 2] == '--' 
    i =[-2, 2].to_i
    link.sub!("--#{i}", "--#{i + 1}")
    link = "#{link}--#{1}"
  # If it's nil, we will create a new one, which will have a --i suffix in the link
  post = Posts.first(:link => link) 
Subscribe to my monthly newsletter.
No spam, unsubscribe at any time.