Created
April 5, 2023 23:52
-
-
Save noraworld/7f9e97f1722b4dab853b9c50c969adce to your computer and use it in GitHub Desktop.
Add YAML headers and rename files according to Jekyll format
This file contains hidden or 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
# 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