Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
require 'date'
require 'fileutils'
Dir.glob('page-*').each do |f|
content =
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment