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
3 merge requests!350[release] Regular merge of develop,!349Draft: [release] Regular merge of develop,!331ordering of cards
......@@ -42,6 +42,23 @@ def build_section_start(title, shortcut):
def build_section_end():
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):
legacy_from = []
os.chdir(root)
......@@ -56,12 +73,13 @@ def save_legacy_from(localroot, root, filename):
legacy_from_flag = True
# append lines from the legacy section
if legacy_from_flag and line[0:12]:
if legacy_from_flag:
legacy_from.append(line)
# check for the end of the header
if legacy_from_flag and line[0:3] == "---":
legacy_from_flag = False
break
# change back to the local root
os.chdir(localroot)
......@@ -75,6 +93,7 @@ def remove_header(localroot, root, filename):
# count the number of lines
count = 0
n = 0
headerCheck = False
with open(filename, 'r') as f:
for line in f:
......@@ -149,6 +168,7 @@ for folder in cardDirs:
if len(localIndexArr[indexS]) == 0:
localIndexArr[indexS] = ["\n"]
orderArr = []
# walk through the folders with all the cards
for root, dirs, files in os.walk(folder+"/"+d):
for file in files:
......@@ -159,7 +179,8 @@ for folder in cardDirs:
if file[0] != "_":
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)
# remove the previous header
......@@ -179,6 +200,9 @@ for folder in cardDirs:
# define the header for each card
header = "---\n"
if len(order) > 0:
header += "order: " + str(order) + "\n"
orderArr.append(int(order))
header += "layout: page\n"
header += "permalink: " + permalink + "\n"
header += "shortcut: " + root_handbook(shortcut) + "\n"
......@@ -235,8 +259,18 @@ for folder in cardDirs:
print(" + New header added.")
print("-----------------------")
# join all subcategories to the index
localIndexArr[indexS] = natsorted(localIndexArr[indexS])
print(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)
......
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