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

add draft to base index generation on a given order

parent 09047b55
No related branches found
No related tags found
No related merge requests found
...@@ -42,6 +42,23 @@ def build_section_start(title, shortcut): ...@@ -42,6 +42,23 @@ def build_section_start(title, shortcut):
def build_section_end(): def build_section_end():
return "\t\t</ul>\n\t</div>" return "\t\t</ul>\n\t</div>"
def save_order(localroot, root, filename):
order = ""
os.chdir(root)
with open(filename, 'r') as f:
for line in f:
# check for the start of the section
#print(line)
if line[0:6] == "order:":
order = line[7:]
break
# change back to the local root
os.chdir(localroot)
return order.rstrip()
def save_legacy_from(localroot, root, filename): def save_legacy_from(localroot, root, filename):
legacy_from = [] legacy_from = []
os.chdir(root) os.chdir(root)
...@@ -56,12 +73,13 @@ def save_legacy_from(localroot, root, filename): ...@@ -56,12 +73,13 @@ def save_legacy_from(localroot, root, filename):
legacy_from_flag = True legacy_from_flag = True
# append lines from the legacy section # append lines from the legacy section
if legacy_from_flag and line[0:12]: if legacy_from_flag:
legacy_from.append(line) legacy_from.append(line)
# check for the end of the header # check for the end of the header
if legacy_from_flag and line[0:3] == "---": if legacy_from_flag and line[0:3] == "---":
legacy_from_flag = False legacy_from_flag = False
break
# change back to the local root # change back to the local root
os.chdir(localroot) os.chdir(localroot)
...@@ -75,6 +93,7 @@ def remove_header(localroot, root, filename): ...@@ -75,6 +93,7 @@ def remove_header(localroot, root, filename):
# count the number of lines # count the number of lines
count = 0 count = 0
n = 0
headerCheck = False headerCheck = False
with open(filename, 'r') as f: with open(filename, 'r') as f:
for line in f: for line in f:
...@@ -149,6 +168,7 @@ for folder in cardDirs: ...@@ -149,6 +168,7 @@ for folder in cardDirs:
if len(localIndexArr[indexS]) == 0: if len(localIndexArr[indexS]) == 0:
localIndexArr[indexS] = ["\n"] localIndexArr[indexS] = ["\n"]
orderArr = []
# walk through the folders with all the cards # walk through the folders with all the cards
for root, dirs, files in os.walk(folder+"/"+d): for root, dirs, files in os.walk(folder+"/"+d):
for file in files: for file in files:
...@@ -159,7 +179,8 @@ for folder in cardDirs: ...@@ -159,7 +179,8 @@ for folder in cardDirs:
if file[0] != "_": if file[0] != "_":
print(" > Generating header for: " + fileName) print(" > Generating header for: " + fileName)
# save legacy section # save order and legacy section
order = save_order(localroot, root, file)
legacy_from = save_legacy_from(localroot, root, file) legacy_from = save_legacy_from(localroot, root, file)
# remove the previous header # remove the previous header
...@@ -179,6 +200,9 @@ for folder in cardDirs: ...@@ -179,6 +200,9 @@ for folder in cardDirs:
# define the header for each card # define the header for each card
header = "---\n" header = "---\n"
if len(order) > 0:
header += "order: " + str(order) + "\n"
orderArr.append(int(order))
header += "layout: page\n" header += "layout: page\n"
header += "permalink: " + permalink + "\n" header += "permalink: " + permalink + "\n"
header += "shortcut: " + root_handbook(shortcut) + "\n" header += "shortcut: " + root_handbook(shortcut) + "\n"
...@@ -235,8 +259,18 @@ for folder in cardDirs: ...@@ -235,8 +259,18 @@ for folder in cardDirs:
print(" + New header added.") print(" + New header added.")
print("-----------------------") print("-----------------------")
# join all subcategories to the index print(localIndexArr[indexS])
localIndexArr[indexS] = natsorted(localIndexArr[indexS]) print(orderArr)
if len(orderArr) > 0:
Y = orderArr
X = localIndexArr[indexS][1:]
print("here")
localIndexArr[indexS] = [x for _, x in sorted(zip(Y, X))]
print(localIndexArr[indexS])
else:
# join all subcategories to the index
localIndexArr[indexS] = natsorted(localIndexArr[indexS])
print(localIndexArr) print(localIndexArr)
......
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