ayaniimi213
7/12/2017 - 2:40 PM

wri.pe2hubedit.rb

require 'date'
require 'fileutils'

Dir.glob('page-*').each do |f|
  content = File.read(f)
  title = content.partition("\n")[0]
  body = content.partition("\n")[2]
  next if body.empty?
  next if title.split(' ').empty?
  splitted = title.split(' ')
  date = splitted.shift
  splitted = ['NOTITLE'] if splitted.empty?
  dir = Date.parse(date).strftime('notes/%Y/%m/%d')
  FileUtils.mkdir_p(dir) unless FileTest.exist?(dir)
  filepath = "#{dir}/#{splitted.join(' ').gsub(/\//,'_')}.md"
  File.write(filepath, body)
end