Last active
April 23, 2018 06:31
-
-
Save xiejiangzhi/9e08f7744179bb1ac569c441771faf6a 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
#!/usr/bin/env ruby | |
def generate_dir_links(dir) | |
level_names = [] | |
last_level = 0 | |
Dir['*.md'].sort.each_with_object([]) do |file, md| | |
next if file == 'Home.md' | |
path = file.split('--') | |
name = path.last | |
path[0..-2].each_with_index do |lname, index| | |
if level_names[index] != lname | |
l_str = " " * index | |
md << l_str + "- #{lname.gsub(/-+/, ' ')}" | |
last_level = index | |
end | |
end | |
level_names = path[0..-2] | |
level_str = " " * (path.length - 1) | |
link = level_str + "- [#{name.gsub('.md', '').gsub(/-+/, ' ')}](#{file.gsub('.md', '')})" | |
md << link | |
end | |
end | |
File.write('Home.md', generate_dir_links('.').join("\n")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment