Skip to content
Snippets Groups Projects
Verified Commit 5898e4da authored by Laurent Heirendt's avatar Laurent Heirendt :airplane:
Browse files

merge 2 operations into 1 loop

parent 3fe4b5c0
No related branches found
No related tags found
2 merge requests!72Regular merge of develop,!70Major update: streamline repository
......@@ -49,55 +49,15 @@ def remove_header(localroot, root, filename, n=5):
# loop through the entire internal tree
localroot = os.getcwd()
for root, dirs, files in os.walk(folder):
for file in files:
if file.endswith(".md"):
fileName = os.path.join(root, file)
# ignore subsections (.md files that start with _)
if file[0] != "_":
print(" > Generating header for: " + fileName)
# remove the previous header
remove_header(localroot, root, file, 8)
# generate a permalink
permalink = "/" + root + "/"
# generate the shortcut
shortcut = re.sub(folder, '', root)
# remove the first /
shortcut = shortcut[1:]
# replace the / with a :
shortcut = re.sub('/', ':', shortcut)
# define the header for each card
header = "---\n"
header += "layout: page\n"
header += "permalink: " + permalink + "\n"
header += "shortcut: " + shortcut + "\n"
header += "redirect_from:\n"
header += " - /cards/" + shortcut + "\n"
header += " - /internal/cards/" + shortcut + "\n"
header += "---"
# add the header properly speaking
line_prepender(fileName, header)
#print(permalink)
# output
print(" + New header added.")
print("-----------------------")
# generate the index properly speaking
dirs = os.listdir(folder)
dirs = sorted(dirs)
index = ""
for d in dirs:
print("### " + d.capitalize())
index += "### " + d.capitalize() + "\n"
for root, dirs, files in os.walk(folder+"/"+d):
for file in files:
......@@ -106,10 +66,35 @@ for d in dirs:
# ignore subsections (.md files that start with _)
if file[0] != "_":
print(" > Generating header for: " + fileName)
# remove ./ from root
# remove the previous header
remove_header(localroot, root, file, 8)
#print(" > Adding " + fileName + " to index ...")
# generate a permalink
permalink = "/" + root + "/"
# generate the shortcut
shortcut = re.sub(folder, '', root)
# remove the first /
shortcut = shortcut[1:]
# replace the / with a :
shortcut = re.sub('/', ':', shortcut)
# define the header for each card
header = "---\n"
header += "layout: page\n"
header += "permalink: " + permalink + "\n"
header += "shortcut: " + shortcut + "\n"
header += "redirect_from:\n"
header += " - /cards/" + shortcut + "\n"
header += " - /internal/cards/" + shortcut + "\n"
header += "---"
# add the header properly speaking
line_prepender(fileName, header)
# open file and get the title after the header
count = 0
......@@ -121,9 +106,15 @@ for d in dirs:
title = line
break
# remove first and last chars
title = title.rstrip("\n\r")
title = title[2:]
print(" * [" + title + "](./" + root + "/")
\ No newline at end of file
index += " * [" + title + "](./" + root + "/" + "\n"
# output
print(" + New header added.")
print("-----------------------")
# output the index
print(index)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment