Skip to content

Instantly share code, notes, and snippets.

@kenjiskywalker kenjiskywalker/op2hg.rb
Last active Oct 11, 2016

Embed
What would you like to do?
To Hugo from Octpress adapt content dirs.
#/usr/bin/env ruby
require 'fileutils'
DIR = "./content/post/"
Dir.chdir(DIR)
# FIX: date format
# find ./content/post/ -type f -exec sed -i "" -e 's/date: \([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\) \([0-9]\{2\}:[0-9]\{2\}\).*$/date: \1T\2:00+09:00/g' {} \;
# BEFORE: content/post/2013-03-09-monitoringcasualvol3.markdown
# AFTER: content/post/2013/03/09/monitoringcasualvol3.markdown
list = `ls ./`.split("\n")
list.each do |f|
next if File.directory?(f)
/([0-9]{4}-[0-9]{2}-[0-9]{2}-)(.*$)/ =~ f
y, m, d = Regexp.last_match(0).split("\-")
file_name = Regexp.last_match(2)
Dir.mkdir("./#{y}") unless File.directory?("./#{y}")
Dir.mkdir("./#{y}/#{m}") unless File.directory?("./#{y}/#{m}")
Dir.mkdir("./#{y}/#{m}/#{d}") unless File.directory?("./#{y}/#{m}/#{d}")
moved_file = "./#{y}/#{m}/#{d}/#{file_name}"
FileUtils.cp(f, moved_file)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.