Skip to content

Instantly share code, notes, and snippets.

@kenjiskywalker
Last active October 11, 2016 07:46
Show Gist options
  • Save kenjiskywalker/d28e1840c56c6b05113a7b4ef2a51c07 to your computer and use it in GitHub Desktop.
Save kenjiskywalker/d28e1840c56c6b05113a7b4ef2a51c07 to your computer and use it in GitHub Desktop.
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