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

cleaning up the script to generate headers

parent 0104d3b6
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,6 @@ def remove_header(localroot, root, filename, n=5):
# check if the header is actually a header
if (count == 0 or count == n) and line[0:3] == "---":
print("existing header detected: " + line[0:2] )
headerCheck = True
# remove the header
......@@ -40,7 +39,7 @@ def remove_header(localroot, root, filename, n=5):
os.remove(filename)
os.rename("tmp"+filename, filename)
print("Header removed: " + filename)
print(" - Old header removed.")
# change back to the local root
os.chdir(localroot)
......@@ -53,10 +52,11 @@ for root, dirs, files in os.walk(folder):
for file in files:
if file.endswith(".md"):
fileName = os.path.join(root, file)
#ignore subsections
#ignore subsections (.md files that start with _)
if file[0] != "_":
#print(localroot)
print("root: " + root + " file: " + file)
print(" > Generating header for: " + fileName)
# remove the previous header
remove_header(localroot, root, file, 8)
......@@ -69,8 +69,10 @@ for root, dirs, files in os.walk(folder):
# 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"
......@@ -80,5 +82,9 @@ for root, dirs, files in os.walk(folder):
header += " - /internal/cards/" + shortcut + "\n"
header += "---"
#print(header)
# add the header properly speaking
line_prepender(fileName, header)
# output
print(" + New header added.")
print("-----------------------")
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