INNER CODE UNIT · Python

collect

rust-lang/rfcs · generate-book.py:49

def collect(summary, path, depth):
    entries = [e for e in os.scandir(path) if e.name.endswith('.md')]
    entries.sort(key=lambda e: e.name)
    for entry in entries:
        indent = '    '*depth
        name = entry.name[:-3]
        link_path = entry.path[5:]
        summary.write(f'{indent}- [{name}]({link_path})\n')
        maybe_subdir = os.path.join(path, name)
        if os.path.isdir(maybe_subdir):
            collect(summary, maybe_subdir, depth+1)

def symlink(src, dst):
    if not os.path.exists(dst):
        os.symlink(src, dst)

if __name__ == '__main__':
    main()

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…