Created
April 4, 2016 04:21
-
-
Save xcodebuild/455dd5733043fe96ee40baab7ff1571e to your computer and use it in GitHub Desktop.
Generate sidebar for github wiki
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
| import os | |
| def createIndexFile(startpath, indexFile): | |
| for root, dirs, files in os.walk(startpath): | |
| files = [f for f in files if not (f[0] == '.' or f[0] == '_')] | |
| dirs[:] = [d for d in dirs if not (d[0] == '.' or d[0] == '_')] | |
| level = root.replace(startpath, '').count(os.sep) - 1 | |
| indent = ' ' * 2 * (level) | |
| directory = os.path.basename(root) | |
| if directory != '.': | |
| indexFile.write('{}- {}\n'.format(indent, os.path.basename(root))) | |
| subindent = ' ' * 2 * (level + 1) | |
| for f in files: | |
| indexFile.write('{}- [{}]({})\n'.format(subindent, f[:-3], f[:-3])) | |
| indexFile = open('_Sidebar.md', 'w') | |
| createIndexFile(".", indexFile) | |
| indexFile.close(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment