Skip to content

Instantly share code, notes, and snippets.

@k1LoW
Created July 12, 2017 14:40
Show Gist options
  • Save k1LoW/ea597c7e5f7cf0ce04a740a9ac9a7cd6 to your computer and use it in GitHub Desktop.
Save k1LoW/ea597c7e5f7cf0ce04a740a9ac9a7cd6 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment