feat: update-toc handles files in root directory

This commit is contained in:
Glenn Y. Rolland 2021-06-27 23:35:59 +02:00
parent 769fe66263
commit 73651fce79

View file

@ -45,27 +45,27 @@ class TocBuilder:
# compute absolute and relative path # compute absolute and relative path
abs_path = os.path.join(root, fn) abs_path = os.path.join(root, fn)
rel_path = os.path.relpath(abs_path, self.root_path) rel_path = os.path.relpath(abs_path, self.root_path)
# split name into parts # split name into parts
bname = os.path.basename(rel_path) bname = os.path.basename(rel_path)
bname_split = os.path.splitext(bname) bname_split = os.path.splitext(bname)
dname = os.path.dirname(rel_path) dname = os.path.dirname(rel_path)
# skip files in docs/ root
# if dname == "":
# continue
# skip files starting with '_' # skip files starting with '_'
#if bname_split[0][0] == '_': #if bname_split[0][0] == '_':
if self.is_masked(rel_path): if self.is_masked(rel_path):
print("Found {} which is masked. Ignoring".format(fn)) print("Found {} which is masked. Ignoring".format(fn))
continue continue
# skip files in docs/ root
# if dname == "":
# continue
# skip index files # skip index files
if bname_split[0] == 'index': if bname_split[0] == 'index':
print("Found {} which is an index file. Ignoring".format(fn)) print("Found {} which is an index file. Ignoring".format(fn))
continue continue
# keep only .md files # keep only .md files
print("* keeping {}".format(rel_path)) print("* keeping {}".format(rel_path))
if bname_split[1] == '.md': if bname_split[1] == '.md':
@ -91,7 +91,11 @@ class TocBuilder:
else: else:
lines.append(" - \"%s\":" % dname) lines.append(" - \"%s\":" % dname)
lines.append(" - %s" % f) if dname != "":
lines.append(" - %s" % f)
else:
lines.append(" - %s" % f)
return lines return lines
class FileInjector: class FileInjector: