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

WIP: generate index script

parent 3bebbfd8
No related branches found
No related tags found
No related merge requests found
...@@ -148,7 +148,10 @@ index += '\n<div class="index-box-container">\n' ...@@ -148,7 +148,10 @@ index += '\n<div class="index-box-container">\n'
whiteList = '' whiteList = ''
localIndexArr = [[]] * len(sections) localIndexArr = [[]] * len(sections)
orderArr = [[]] * len(sections)
for folder in cardDirs: for folder in cardDirs:
# FolderFlag gets set to true at the first iteration
folderFlag = True
# check if folder exists # check if folder exists
if path.isdir(folder): if path.isdir(folder):
...@@ -163,12 +166,12 @@ for folder in cardDirs: ...@@ -163,12 +166,12 @@ for folder in cardDirs:
# get the index of the section # get the index of the section
indexS = sections.index(d) indexS = sections.index(d)
maxOrder = 0
#print(indexS) #print(indexS)
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:
...@@ -200,9 +203,38 @@ for folder in cardDirs: ...@@ -200,9 +203,38 @@ for folder in cardDirs:
# define the header for each card # define the header for each card
header = "---\n" header = "---\n"
print(orderArr)
if len(order) > 0: if len(order) > 0:
header += "order: " + str(order) + "\n" header += "order: " + str(order) + "\n"
orderArr.append(int(order)) # append the order of the card
# find the maximum of existing orders
if folderFlag:
if len(orderArr[indexS]) > 0:
maxOrder = max(orderArr[indexS])
else:
maxOrder = 0
# after determining the max order, set the folder flag to False to avoid another entry into the same block of code
folderFlag = False
tmp = orderArr[indexS]
print("tmp")
print(tmp)
tmp.append(maxOrder + int(order))
orderArr[indexS] = tmp
print(tmp)
else:
orderArr[indexS] = []
print(orderArr)
print("maxOrder: " + str(maxOrder))
print("folderFlag: " + str(folderFlag))
print("indexS: " + str(indexS))
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"
...@@ -259,10 +291,15 @@ for folder in cardDirs: ...@@ -259,10 +291,15 @@ for folder in cardDirs:
print(" + New header added.") print(" + New header added.")
print("-----------------------") print("-----------------------")
if len(orderArr) > 0: if len(orderArr[indexS]) > 0:
print("here")
print(localIndexArr[indexS])
print(orderArr[indexS])
X = localIndexArr[indexS][1:] X = localIndexArr[indexS][1:]
Y = orderArr Y = orderArr[indexS]
localIndexArr[indexS] = [x for _, x in sorted(zip(Y, X))] localIndexArr[indexS] = [x for _, x in sorted(zip(Y, X))]
print(localIndexArr[indexS])
else: else:
# join all subcategories to the index # join all subcategories to the index
localIndexArr[indexS] = natsorted(localIndexArr[indexS]) localIndexArr[indexS] = natsorted(localIndexArr[indexS])
......
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