scripts: Improve update-toc

This commit is contained in:
Glenn Y. Rolland 2020-11-11 10:52:15 +01:00
parent 0ad4cf46e5
commit dce9e69a35
2 changed files with 7 additions and 3 deletions

View file

@ -92,7 +92,7 @@ tocupdate:
while inotifywait -q -e move -e modify -e create -e attrib -e delete -e moved_to -r docs ; do \
sleep 0.2 ; \
make images ; \
pipenv run ./scripts/update-toc ; \
pipenv run ./scripts/update-toc $(DOCS_DIR) ; \
done
$(BUILD_SLIDES_DIR)/%.pdf: $(SLIDES_DIR)/%.md

View file

@ -32,6 +32,7 @@ class TocBuilder:
md_files = []
for root, dirs, files in os.walk(self.root_path):
for fn in files:
print("Found {}".format(fn))
# compute absolute and relative path
abs_path = os.path.join(root, fn)
rel_path = os.path.relpath(abs_path, self.root_path)
@ -50,8 +51,10 @@ class TocBuilder:
continue
# keep only .md files
print("* keeping {}".format(rel_path))
if bname_split[1] == '.md':
md_files.append(rel_path)
return md_files
def format(self, md_files):
@ -115,9 +118,10 @@ class FileInjector:
# save part before
@click.command()
def build():
@click.argument('docs_directory')
def build(docs_directory):
root_path = Path(__file__).parent.parent
toc = TocBuilder(str(root_path / 'docs'))
toc = TocBuilder(docs_directory)
md_files = toc.lookup()
md_toc = toc.format(md_files)
fi = FileInjector('MKDOCS-TOC')