Gitlab migration complete. If you have any issue please read the FAQ.

Verified Commit bfaeafdb authored by Laurent Heirendt's avatar Laurent Heirendt
Browse files

proper section ordering

parent 08c2c906
......@@ -52,83 +52,116 @@ localroot = os.getcwd()
# generate the index properly speaking
dirs = os.listdir(folder)
dirs = sorted(dirs)
index = ""
cardDirs = ["internal", "external"]
sections = []
# determine first the directories
for direct in cardDirs:
dirs = os.listdir(direct)
for d in dirs:
if d[0] != ".":
sections.append(d)
for d in dirs:
if d[0] != ".":
# set the header of the section
index += "\n### " + d.replace("-", " ").capitalize() + "\n"
localIndexArr = ["\n"]
# walk through the folders with all the cards
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] != "_":
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)
# open file and get the title after the header
count = 0
title = ""
bp = 9
with open(fileName, 'r') as f:
for line in f:
count += 1
if count == bp:
if len(line) > 2:
title = line
break
else:
bp += 1
# remove first and last chars
title = title.rstrip("\n\r")
title = title[2:]
#index += " * [" + title + "](./" + root + "/" + "\n"
localIndexArr.append("* [" + title + "](./" + root + "/" + ")\n")
# output
print(" + New header added.")
print("-----------------------")
# join all subcategories to the index
localIndexArr.sort()
index += ''.join(localIndexArr)
sections = list(set(sections))
sections.sort()
index = ""
localIndexArr = [[]] * len(sections)
for folder in cardDirs:
# check here if folder exists
dirs = os.listdir(folder)
dirs = sorted(dirs)
for d in dirs:
if d[0] != ".":
# set the header of the section
#index += "\n### " + d.replace("-", " ").capitalize() + "\n"
# get the index of the section
indexS = sections.index(d)
#print(indexS)
if len(localIndexArr[indexS]) == 0:
localIndexArr[indexS] = ["\n"]
# walk through the folders with all the cards
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] != "_":
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)
# open file and get the title after the header
count = 0
title = ""
bp = 9
with open(fileName, 'r') as f:
for line in f:
count += 1
if count == bp:
if len(line) > 2:
title = line
break
else:
bp += 1
# remove first and last chars
title = title.rstrip("\n\r")
title = title[2:]
#index += " * [" + title + "](./" + root + "/" + "\n"
localIndexArr[indexS].append("* [" + title + "](./" + root + "/" + ")\n")
# output
print(" + New header added.")
print("-----------------------")
# join all subcategories to the index
localIndexArr[indexS].sort()
#index += ''.join(localIndexArr)
print(localIndexArr)
# determine the index
k = 0
for s in sections:
index += "\n### " + s.replace("-", " ").capitalize() + "\n"
index += ''.join(localIndexArr[k])
k += 1
# output the index
#print(index)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment