Skip to content

Instantly share code, notes, and snippets.

@matsubara0507
Created December 3, 2018 04:30
Show Gist options
  • Save matsubara0507/d8608e17ffc8156e1c543e9b15d5b2ee to your computer and use it in GitHub Desktop.
Save matsubara0507/d8608e17ffc8156e1c543e9b15d5b2ee to your computer and use it in GitHub Desktop.
MD -> Hugo の frontmatter をたす
path = ENV['path']
files = `ls -d #{path}/*`.split("\n")
p files
files.each do |filepath|
cont = File.read(filepath)
title, body = cont.split("\n", 2)
next unless title.start_with?('# ')
date = filepath.sub(/^content\/blog\//, '').tr('/', '-').sub(/\.md$/, '')
frontmatter = [
"---",
"titile: \"#{title.sub(/^\# /, '')}\"",
"date: #{date}",
"---\n"].join("\n")
puts frontmatter
File.write(filepath, frontmatter + body)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment