Last active
September 16, 2023 13:52
-
-
Save evantravers/dbe040f37c3b10fcf82f5296435a2fa1 to your computer and use it in GitHub Desktop.
This file contains 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
Dir.glob("./**/*.md").each do |file| | |
filename = File.basename(file, '.md') | |
content = File.read(file) | |
lines = content.lines | |
matching_title = lines.find_index { |l| l.match /^# #{filename}\s*$/ } | |
if matching_title then | |
# find block of empty lines | |
blank_lines = matching_title + 1 | |
while lines[blank_lines] and lines[blank_lines].match(/^\s*$/) do | |
blank_lines += 1 | |
end | |
lines.slice!(matching_title..blank_lines - 1) | |
File.write(file, lines.join) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment