Skip to content

Instantly share code, notes, and snippets.

@ggarnier
Created February 4, 2014 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ggarnier/8812725 to your computer and use it in GitHub Desktop.
Save ggarnier/8812725 to your computer and use it in GitHub Desktop.
Add date to Octopress posts
Dir.glob("source/_posts/*.markdown").each do |filename|
formatted_date = filename.split("/").last[0..9]
puts "Adding date #{formatted_date} to file #{filename}"
lines = []
IO.readlines(filename).map do |line|
lines << line
lines << "date: #{formatted_date}" if line =~ /^title: /
end
File.open(filename, 'w') do |file|
file.puts lines
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment