Update DIRECTORY (#1161)

* Update DIRECTORY

* Updated DIRECTORY

* Fixed bug in directory build and re-build the directory.md

* fixed url issue

* fixed indentation in Directory.md
This commit is contained in:
Jai Kumar Dewani
2019-09-06 14:32:37 +05:30
committed by Christian Clauss
parent 2dfe01e4d8
commit ab25079e16
2 changed files with 117 additions and 511 deletions

View File

@ -14,7 +14,7 @@ def good_filepaths(top_dir: str = ".") -> Iterator[str]:
continue
if os.path.splitext(filename)[1] in (".py", ".ipynb"):
yield os.path.join(dirpath, filename).lstrip("./")
def md_prefix(i):
return f"{i * ' '}*" if i else "##"
@ -25,7 +25,7 @@ def print_path(old_path: str, new_path: str) -> str:
for i, new_part in enumerate(new_path.split(os.sep)):
if i + 1 > len(old_parts) or old_parts[i] != new_part:
if new_part:
print(f"{md_prefix(i)} {new_part.replace('_', ' ').title()}")
print(f"{md_prefix(i-1)} {new_part.replace('_', ' ').title()}")
return new_path
@ -36,7 +36,7 @@ def print_directory_md(top_dir: str = ".") -> None:
if filepath != old_path:
old_path = print_path(old_path, filepath)
indent = (filepath.count(os.sep) + 1) if filepath else 0
url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20")
url = "/".join((URL_BASE, filepath.split(os.sep)[1], filename)).replace(" ", "%20")
filename = os.path.splitext(filename.replace("_", " "))[0]
print(f"{md_prefix(indent)} [{filename}]({url})")