小法师系列

每个程序员上辈纸都是法力无边的巫师

ruby README.md to generate SUMMARY.MD
  1. def main
  2. files = Dir['Contents/*.md']
  3. url = "Contents/"
  4. lists = {}
  5. for file in files
  6. File.open(file) do | text |
  7. text.each_line { |line|
  8. if line.include?"\#"
  9. lists[file.delete("Contents/" ".md")] = line.chomp.delete("\#")
  10. break
  11. end
  12. }
  13. end
  14. end
  15. lists.keys.sort
  16. File.open("SUMMARY.md", "w") do |file|
  17. for k, v in lists
  18. link = "1. " + "[" + v + "](" + url + k +".md)"
  19. file.puts link
  20. end
  21. end
  22. end
  23. if __FILE__ == $0
  24. main()
  25. end

来源(书栈小编注)

https://github.com/Artwalk/LittleMaster