Guest User

Untitled

a guest
May 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.82 KB | None | 0 0
  1. #!/home/matt/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
  2. #
  3. # Create new jekyll post and open it
  4. # $ ruby _new.rb This is the title
  5.  
  6. # The arguments form the title
  7. unless ARGV[0]
  8.   raise "Please provide a post title."
  9. end
  10.  
  11. # Create a URL slug from the title
  12. def slugify(title)
  13.     str = title.dup
  14.     str.gsub!(/[^a-zA-Z0-9 ]/,"")
  15.     str.gsub!(/[ ]+/," ")
  16.     str.gsub!(/ /,"-")
  17.     str.downcase!
  18.     str
  19. end
  20.  
  21. # Create parameters
  22. title  = ARGV.join(' ')
  23. slug   = slugify(title)
  24. year   = Time.new.year.to_s
  25. prefix = Time.new.strftime("%Y-%m-%d")
  26. file   = "#{prefix}-#{slug}.markdown"
  27. path   = File.join(File.dirname(__FILE__), "_posts/#{year}/#{file}")
  28. text   = <<-eos
  29. ---
  30. title: #{title}
  31. layout: post
  32. ---
  33.  
  34. eos
  35.  
  36. # Create a new file and open it in VIM MOTHERfuCKER
  37. File.open(path, 'w') { |f| f.write(text) }
  38. system("vim #{path}")
Add Comment
Please, Sign In to add comment