Last active
June 9, 2016 10:28
-
-
Save aq2bq/3af4b375974fe3d76eb24a315cdadabe to your computer and use it in GitHub Desktop.
Summary Generator for mdBook
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
require 'pathname' | |
PATHS = Pathname.glob('./src/**/[^SUMMARY]*.md') | |
paths = PATHS.each_with_object({}) do |path, dirs| | |
unless dirs[path.parent] | |
dirs[path.parent] = [] | |
end | |
dirs[path.parent] << path | |
end | |
File.open('./src/SUMMARY.md', 'w') do |f| | |
f.puts("# Summary") | |
paths.each_key do |k| | |
f.puts "" | |
dirname = k.to_s.gsub('./src', '').upcase | |
f.puts("## #{dirname}") | |
paths[k].each do |path| | |
title = path.basename.to_s.gsub('_', ' ').gsub('.md', '').upcase | |
f.puts "- [#{dirname} > #{title}](#{path.to_s.gsub('/src', '')})" | |
end | |
end | |
end | |
system 'mdbook build' | |
system 'more ./src/SUMMARY.md' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment