Skip to content

Instantly share code, notes, and snippets.

@matsubara0507
Created December 3, 2018 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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