docmachine-containers/bin/extract-toc
2018-04-20 17:27:59 +02:00

26 lines
380 B
Ruby
Executable file

#!/usr/bin/env ruby
require 'sanitize'
h1 = ""
h2 = ""
Dir['slides/**/*.md'].sort.each do |name|
content = File.read(name)
oldh1 = h1
oldh2 = h2
if content =~ /^# (.*)\n/
h1 = $1
end
if content =~ /^### (.*)\n/
h2 = $1
end
if oldh1 != h1
puts ""
puts "#{Sanitize.clean(h1)}"
end
if oldh2 != h2
puts "- #{Sanitize.clean(h2)}"
end
end