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

Merge branch 'issue-37' into 'develop'

ordering of cards

See merge request !331
parents 09047b55 2d7ee485
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
Pipeline #52537 passed with warnings
Showing
with 100 additions and 11 deletions
......@@ -42,6 +42,35 @@ 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
if line[0:6] == "order:":
order = line[7:]
break
# change back to the local root
os.chdir(localroot)
return order.rstrip()
def get_ignore():
return ["404.html",
"Gemfile",
"Gemfile.lock",
"README.md",
"_config.yml",
"_site",
"assets",
"help.md",
"index.md",
"pagination.md"
]
def save_legacy_from(localroot, root, filename):
legacy_from = []
os.chdir(root)
......@@ -56,12 +85,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 +105,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:
......@@ -105,6 +136,8 @@ def remove_header(localroot, root, filename):
# loop through the entire internal tree
localroot = os.getcwd()
# retrieve ignore list
ignore = get_ignore()
# generate the index properly speaking
cardDirs = ["internal", "external", "policies"]
......@@ -117,7 +150,7 @@ for direct in cardDirs:
dirs = natsorted(dirs)
for d in dirs:
if d[0] != ".":
if d[0] != "." and d not in ignore:
sections.append(d)
sections = list(set(sections))
......@@ -128,24 +161,27 @@ index = ''
index += '\n<div class="index-box-container">\n'
whiteList = ''
localIndexArr = [[]] * len(sections)
localIndexArr = {k: [] for k in range(len(sections))}
orderArr = {k: [] for k in range(len(sections))}
for folder in cardDirs:
# FolderFlag gets set to true at the first iteration
folderFlag = True
# check if folder exists
if path.isdir(folder):
if path.isdir(folder) and folder not in ignore:
dirs = os.listdir(folder)
dirs = natsorted(dirs)
for d in dirs:
if d[0] != ".":
if d[0] != "." and d not in ignore:
# set the header of the section
#index += "\n### " + d.replace("-", " ").capitalize() + "\n"
# get the index of the section
indexS = sections.index(d)
maxOrder = 0
#print(indexS)
if len(localIndexArr[indexS]) == 0:
localIndexArr[indexS] = ["\n"]
......@@ -159,7 +195,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 +216,26 @@ for folder in cardDirs:
# define the header for each card
header = "---\n"
if len(order) > 0:
header += "order: " + str(order) + "\n"
# 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].copy()
tmp.append(maxOrder + int(order))
orderArr[indexS] = tmp
else:
orderArr[indexS] = []
header += "layout: page\n"
header += "permalink: " + permalink + "\n"
header += "shortcut: " + root_handbook(shortcut) + "\n"
......@@ -235,8 +292,21 @@ for folder in cardDirs:
print(" + New header added.")
print("-----------------------")
# join all subcategories to the index
localIndexArr[indexS] = natsorted(localIndexArr[indexS])
# ordering of cards
for d in sections:
indexS = sections.index(d)
# join all subcategories to the index
# if all subcategories have a predefined order
if len(orderArr[indexS]) == len(localIndexArr[indexS])-1 and len(orderArr[indexS]) > 0:
print("")
X = localIndexArr[indexS][1:]
Y = orderArr[indexS]
localIndexArr[indexS] = [x for _, x in sorted(zip(Y, X))]
# natural sorting otherwise
else:
localIndexArr[indexS] = natsorted(localIndexArr[indexS])
print(localIndexArr)
......
---
order: 100
layout: page
permalink: /external/access/harrenhal-access/
shortcut: access:harrenhal-access
......
---
order: 200
layout: page
permalink: /external/access/lums-passwords/
shortcut: access:lums-passwords
......
---
order: 300
layout: page
permalink: /external/access/passwords/
shortcut: access:passwords
......
---
order: 400
layout: page
permalink: /external/access/vpn-cerbere-access/
shortcut: access:vpn-cerbere-access
......
---
order: 500
layout: page
permalink: /external/access/wifiNetworkAccessGuests/
shortcut: access:wifiNetworkAccessGuests
......
---
order: 100
layout: page
permalink: /external/backup/computer/
shortcut: backup:computer
......
---
order: 300
layout: page
permalink: /external/general/BelvalCampusMap/
shortcut: general:BelvalCampusMap
......
---
order: 900
layout: page
permalink: /external/general/attend-webex/
shortcut: general:attend-webex
......@@ -21,4 +22,4 @@ You can then login with your university credentials. Once you logged in, a popup
![](img/image2.png)
**Note:** On Windows, you might not be asked for a password.
\ No newline at end of file
**Note:** On Windows, you might not be asked for a password.
---
order: 200
layout: page
permalink: /external/general/getToLCSB/
shortcut: general:getToLCSB
......
---
order: 500
layout: page
permalink: /external/general/glossary/
shortcut: general:glossary
......
---
order: 600
layout: page
permalink: /external/general/links/
shortcut: general:links
......
---
order: 800
layout: page
permalink: /external/general/remote-working/
shortcut: general:remote-working
......
---
order: 100
layout: page
permalink: /external/general/usefulLinks/
shortcut: general:usefulLinks
......
---
order: 200
layout: page
permalink: /external/on-offboarding/checklistArrival/
shortcut: on-offboarding:checklistArrival
......
---
order: 400
layout: page
permalink: /external/on-offboarding/checklistBeforeArriving/
shortcut: on-offboarding:checklistBeforeArriving
......
---
order: 100
layout: page
permalink: /external/on-offboarding/checklistGetStarted/
shortcut: on-offboarding:checklistGetStarted
......
---
order: 300
layout: page
permalink: /external/on-offboarding/checklistGodparent/
shortcut: on-offboarding:checklistGodparent
......
---
order: 600
layout: page
permalink: /external/on-offboarding/godparent/
shortcut: on-offboarding:godparent
......
---
order: 500
layout: page
permalink: /external/on-offboarding/onboarding/
shortcut: on-offboarding:onboarding
......
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