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

WIP: writing index

parent de252ca2
No related branches found
No related tags found
No related merge requests found
import os, re
folder = "external"
def line_prepender(filename, line):
with open(filename, 'r+') as f:
content = f.read()
......@@ -46,14 +48,13 @@ def remove_header(localroot, root, filename, n=5):
#print("exit folder:" + os.getcwd())
# loop through the entire internal tree
folder = "external"
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 _)
# ignore subsections (.md files that start with _)
if file[0] != "_":
print(" > Generating header for: " + fileName)
......@@ -85,6 +86,44 @@ for root, dirs, files in os.walk(folder):
# 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)
for d in dirs:
print("### " + d.capitalize())
for root, dirs, files in os.walk(folder+"/"+d):
for file in files:
if file.endswith(".md"):
fileName = os.path.join(root, file)
# ignore subsections (.md files that start with _)
if file[0] != "_":
# remove ./ from root
#print(" > Adding " + fileName + " to index ...")
# open file and get the title after the header
count = 0
title = ""
with open(fileName, 'r') as f:
for line in f:
count += 1
if count == 9:
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
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