Created
July 12, 2017 14:40
-
-
Save k1LoW/ea597c7e5f7cf0ce04a740a9ac9a7cd6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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