Skip to content

Instantly share code, notes, and snippets.

@verctor
Created October 28, 2019 15:00
Show Gist options
  • Save verctor/6ffbfbb03bc667f4c7ca3913a802b5cb to your computer and use it in GitHub Desktop.
Save verctor/6ffbfbb03bc667f4c7ca3913a802b5cb to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
summary = ''
summary += '# Summary\n'
extend = ' ' * 4
link_format = '* [{title}]({path})\n'
cur_depth = 1
def gen_summary(path):
global cur_depth
tmp = ''
file_list = os.listdir(path)
for f in file_list:
file_path = os.path.join(path, f)
if not os.path.isdir(file_path) and os.path.splitext(f)[1] == '.md':
tmp += extend * (cur_depth - 1) + link_format.format(title=f, path=file_path)
continue
if not os.path.isdir(file_path):
continue
cur_depth += 1
tmp1 = gen_summary(file_path)
if tmp1:
tmp += extend * (cur_depth - 2) + link_format.format(title=f, path='')
tmp += tmp1
cur_depth -= 1
return tmp
if __name__ == '__main__':
import sys
d = sys.argv[1]
summary += gen_summary(d)
print(summary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment