Skip to content

Instantly share code, notes, and snippets.

@evantravers
Last active September 16, 2023 13:52
Show Gist options
  • Save evantravers/dbe040f37c3b10fcf82f5296435a2fa1 to your computer and use it in GitHub Desktop.
Save evantravers/dbe040f37c3b10fcf82f5296435a2fa1 to your computer and use it in GitHub Desktop.
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