Skip to content

Instantly share code, notes, and snippets.

@noraworld
Created April 5, 2023 23:52
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 noraworld/7f9e97f1722b4dab853b9c50c969adce to your computer and use it in GitHub Desktop.
Save noraworld/7f9e97f1722b4dab853b9c50c969adce to your computer and use it in GitHub Desktop.
Add YAML headers and rename files according to Jekyll format
# frozen_string_literal: true
def main
dir = if ARGV.empty?
'**/*'
elsif ARGV.first.end_with?('/')
"#{ARGV.first}**/*"
else
"#{ARGV.first}/**/*"
end
Dir.glob(dir) do |original_file|
if original_file.end_with?('.md')
new_file = original_file.gsub(/.md$/, '-.md')
File.open(new_file, 'w') do |new_file_io|
new_file_io.puts "---\n---\n\n"
File.foreach(original_file) do |original_file_io|
new_file_io.puts original_file_io
end
end
File.delete(original_file)
end
end
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment