diff --git a/.ci/generateIndex.py b/.ci/generateIndex.py index e07ade6ebc502604e1bf014f25b0273c2e955a2c..58109ba3c4d9f80c608072ccf72e5591de5c1fe4 100644 --- a/.ci/generateIndex.py +++ b/.ci/generateIndex.py @@ -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) diff --git a/external/access/harrenhal-access/harrenhal-access.md b/external/access/harrenhal-access/harrenhal-access.md index e935e4b888a1c696608f309f0597c1dfd0f5e3dd..ee22874009605353226c6813b98a6453c395fff2 100644 --- a/external/access/harrenhal-access/harrenhal-access.md +++ b/external/access/harrenhal-access/harrenhal-access.md @@ -1,4 +1,5 @@ --- +order: 100 layout: page permalink: /external/access/harrenhal-access/ shortcut: access:harrenhal-access diff --git a/external/access/lums-passwords/lums-passwords.md b/external/access/lums-passwords/lums-passwords.md index c46fd79db993f044d17b5cda4dc6bc37898901b6..f55d43e9a2bfdcaa50065cc276eaa3ada36d15f8 100644 --- a/external/access/lums-passwords/lums-passwords.md +++ b/external/access/lums-passwords/lums-passwords.md @@ -1,4 +1,5 @@ --- +order: 200 layout: page permalink: /external/access/lums-passwords/ shortcut: access:lums-passwords diff --git a/external/access/passwords/passwords.md b/external/access/passwords/passwords.md index a58dc615fd80fccb0f547f83a252446139e75d7e..6ad2bf57e1e1db351af6ec8269138f3eecbe73dd 100644 --- a/external/access/passwords/passwords.md +++ b/external/access/passwords/passwords.md @@ -1,4 +1,5 @@ --- +order: 300 layout: page permalink: /external/access/passwords/ shortcut: access:passwords diff --git a/external/access/vpn-cerbere-access/vpn-cerbere-access.md b/external/access/vpn-cerbere-access/vpn-cerbere-access.md index f225fbf645472836361c0d5675f4621da753e843..b5db46d738a4832b0f3a66fecba8726ec3f2dc57 100644 --- a/external/access/vpn-cerbere-access/vpn-cerbere-access.md +++ b/external/access/vpn-cerbere-access/vpn-cerbere-access.md @@ -1,4 +1,5 @@ --- +order: 400 layout: page permalink: /external/access/vpn-cerbere-access/ shortcut: access:vpn-cerbere-access diff --git a/external/access/wifiNetworkAccessGuests/wifiNetworkAccessGuests.md b/external/access/wifiNetworkAccessGuests/wifiNetworkAccessGuests.md index e0b26a9901c60f62828d8d7e3ac67672467f28e3..af0735c4bc7c73fe8d5718bd0014ef89ab8377fc 100644 --- a/external/access/wifiNetworkAccessGuests/wifiNetworkAccessGuests.md +++ b/external/access/wifiNetworkAccessGuests/wifiNetworkAccessGuests.md @@ -1,4 +1,5 @@ --- +order: 500 layout: page permalink: /external/access/wifiNetworkAccessGuests/ shortcut: access:wifiNetworkAccessGuests diff --git a/external/backup/computer/computer.md b/external/backup/computer/computer.md index cddcca823a04b51ef119d8c9ecf17e86ec747cf5..fb5148542e0040293fe0ed9718a36afd21265bc3 100644 --- a/external/backup/computer/computer.md +++ b/external/backup/computer/computer.md @@ -1,4 +1,5 @@ --- +order: 100 layout: page permalink: /external/backup/computer/ shortcut: backup:computer diff --git a/external/general/BelvalCampusMap/BelvalCampusMap.md b/external/general/BelvalCampusMap/BelvalCampusMap.md index 64d26b2b2ee4c5b49e5315d96e440fd3d659a122..32e5fef23f43f2d1853669e3ef0911f62e8aa427 100644 --- a/external/general/BelvalCampusMap/BelvalCampusMap.md +++ b/external/general/BelvalCampusMap/BelvalCampusMap.md @@ -1,4 +1,5 @@ --- +order: 300 layout: page permalink: /external/general/BelvalCampusMap/ shortcut: general:BelvalCampusMap diff --git a/external/general/attend-webex/attend-webex.md b/external/general/attend-webex/attend-webex.md index 5220ada8fd3a54e9cab455e74e235076c1a31e02..6f8fb26238a9b770478e1ee291b5883101afefc9 100644 --- a/external/general/attend-webex/attend-webex.md +++ b/external/general/attend-webex/attend-webex.md @@ -1,4 +1,5 @@ --- +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  -**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. diff --git a/external/general/getToLCSB/getToLCSB.md b/external/general/getToLCSB/getToLCSB.md index b59d6e70d50c37d9a91f5ad0de1c6adc62602f9d..36d912c3896444385b42338c4cc304ad69693aa6 100644 --- a/external/general/getToLCSB/getToLCSB.md +++ b/external/general/getToLCSB/getToLCSB.md @@ -1,4 +1,5 @@ --- +order: 200 layout: page permalink: /external/general/getToLCSB/ shortcut: general:getToLCSB diff --git a/external/general/glossary/glossary.md b/external/general/glossary/glossary.md index f54cac517b4d699f957433db7ff8e7285c9bdb80..73553e0e73144a9dd67c35ea06a8ac276d7a0110 100644 --- a/external/general/glossary/glossary.md +++ b/external/general/glossary/glossary.md @@ -1,4 +1,5 @@ --- +order: 500 layout: page permalink: /external/general/glossary/ shortcut: general:glossary diff --git a/external/general/links/important_links.md b/external/general/links/important_links.md index 3234da3b94b2b9001ad4f8a43f8b3acbae5bff53..db2dc4f1f72146baed6065e3c909c273fd5fd3fc 100644 --- a/external/general/links/important_links.md +++ b/external/general/links/important_links.md @@ -1,4 +1,5 @@ --- +order: 600 layout: page permalink: /external/general/links/ shortcut: general:links diff --git a/external/general/remote-working/remote-working.md b/external/general/remote-working/remote-working.md index 0847c3fc53fc8a224f2951df6b9d8769820f21f2..848fe6b3ab267bbd39d7f0fee58a733942297627 100644 --- a/external/general/remote-working/remote-working.md +++ b/external/general/remote-working/remote-working.md @@ -1,4 +1,5 @@ --- +order: 800 layout: page permalink: /external/general/remote-working/ shortcut: general:remote-working diff --git a/external/general/usefulLinks/usefulLinks.md b/external/general/usefulLinks/usefulLinks.md index 691da7fdb98ee85ffd8f57d78b742f3735db8831..bbef834d974a3cc84308b895982927c274b5b2c6 100644 --- a/external/general/usefulLinks/usefulLinks.md +++ b/external/general/usefulLinks/usefulLinks.md @@ -1,4 +1,5 @@ --- +order: 100 layout: page permalink: /external/general/usefulLinks/ shortcut: general:usefulLinks diff --git a/external/on-offboarding/checklistArrival/checklistArrival.md b/external/on-offboarding/checklistArrival/checklistArrival.md index 2c08697fe5ebf0cd2e34a1ce508eaa9570276f7f..99cb157f24750f87025e6fe74f7eabeadd6f667d 100644 --- a/external/on-offboarding/checklistArrival/checklistArrival.md +++ b/external/on-offboarding/checklistArrival/checklistArrival.md @@ -1,4 +1,5 @@ --- +order: 200 layout: page permalink: /external/on-offboarding/checklistArrival/ shortcut: on-offboarding:checklistArrival diff --git a/external/on-offboarding/checklistBeforeArriving/checklistBeforeArriving.md b/external/on-offboarding/checklistBeforeArriving/checklistBeforeArriving.md index 1835221c157bb87d7e85a5918d5a2b1d7729f13f..8357de6db0237156e5ee326be0b4d36c567a5d3d 100644 --- a/external/on-offboarding/checklistBeforeArriving/checklistBeforeArriving.md +++ b/external/on-offboarding/checklistBeforeArriving/checklistBeforeArriving.md @@ -1,4 +1,5 @@ --- +order: 400 layout: page permalink: /external/on-offboarding/checklistBeforeArriving/ shortcut: on-offboarding:checklistBeforeArriving diff --git a/external/on-offboarding/checklistGetStarted/checklistGetStarted.md b/external/on-offboarding/checklistGetStarted/checklistGetStarted.md index 421000d8097fcabc1b9dd7f69e07ddedceef760d..e9996c464d4a11ddecf5da12ed255eea260d731a 100644 --- a/external/on-offboarding/checklistGetStarted/checklistGetStarted.md +++ b/external/on-offboarding/checklistGetStarted/checklistGetStarted.md @@ -1,4 +1,5 @@ --- +order: 100 layout: page permalink: /external/on-offboarding/checklistGetStarted/ shortcut: on-offboarding:checklistGetStarted diff --git a/external/on-offboarding/checklistGodparent/checklistGodparent.md b/external/on-offboarding/checklistGodparent/checklistGodparent.md index f3d13bd19dcb10c6fa4cdbb2275cfda0eed9e256..d0825f7342be3b6e784cc5f84708b2d10bf248ac 100644 --- a/external/on-offboarding/checklistGodparent/checklistGodparent.md +++ b/external/on-offboarding/checklistGodparent/checklistGodparent.md @@ -1,4 +1,5 @@ --- +order: 300 layout: page permalink: /external/on-offboarding/checklistGodparent/ shortcut: on-offboarding:checklistGodparent diff --git a/external/on-offboarding/godparent/godparent.md b/external/on-offboarding/godparent/godparent.md index 1c2a1e3013a56176038c978a4b461779f4b11012..0b9d2256026c1d401b3cd6a3d182364c0878f943 100644 --- a/external/on-offboarding/godparent/godparent.md +++ b/external/on-offboarding/godparent/godparent.md @@ -1,4 +1,5 @@ --- +order: 600 layout: page permalink: /external/on-offboarding/godparent/ shortcut: on-offboarding:godparent diff --git a/external/on-offboarding/onboarding/onboarding.md b/external/on-offboarding/onboarding/onboarding.md index be9577dc9c4ada1699b071e85652a476d7d24ac0..e290136255a6e54a2df830669b3acaf88bf9aa37 100644 --- a/external/on-offboarding/onboarding/onboarding.md +++ b/external/on-offboarding/onboarding/onboarding.md @@ -1,4 +1,5 @@ --- +order: 500 layout: page permalink: /external/on-offboarding/onboarding/ shortcut: on-offboarding:onboarding