Commit f465bde9 authored by Laurent Heirendt's avatar Laurent Heirendt
Browse files

Merge branch 'fix-script' into 'develop'

fix script for handbook links

See merge request !313
parents 59117f63 0b4d5a02
Pipeline #48024 passed with stages
in 2 minutes and 28 seconds
......@@ -15,16 +15,19 @@ def build_link(title, href):
if ('handbook' in href):
title = re.sub('[0-9.]', '', title).strip()
# add relative url
href = "{{ '" + href + "' | relative_url }}"
return f'\t\t\t<li><a href="{href}">{title}</a></li>\n'
def root_handbook(href):
# remove sym link reference in href
if ('handbook-additional' in href):
href = href.replace('handbook-additional', 'handbook').strip()
elif ('handbook-annexes' in href):
href = href.replace('handbook-annexes', 'handbook').strip()
# add relative url
href = "{{ '" + href + "' | relative_url }}"
return f'\t\t\t<li><a href="{href}">{title}</a></li>\n'
return href
def build_section_start(title, shortcut):
......@@ -135,7 +138,10 @@ for folder in cardDirs:
print(" > Generating header for: " + fileName)
# remove the previous header
remove_header(localroot, root, file, 8)
if "handbook-annexes" in fileName or "handbook-additional" in fileName:
remove_header(localroot, root, file, 10)
else:
remove_header(localroot, root, file, 8)
# generate a permalink
permalink = "/" + root + "/"
......@@ -153,10 +159,16 @@ for folder in cardDirs:
header = "---\n"
header += "layout: page\n"
header += "permalink: " + permalink + "\n"
header += "shortcut: " + shortcut + "\n"
header += "shortcut: " + root_handbook(shortcut) + "\n"
header += "redirect_from:\n"
header += " - /cards/" + shortcut + "\n"
header += " - /" + folder + "/cards/" + shortcut + "\n"
# special case of handbook
if "handbook-annexes" in permalink or "handbook-additional" in permalink:
header += " - /cards/" + root_handbook(shortcut) + "\n"
header += " - /" + folder + "/cards/" + root_handbook(shortcut) + "\n"
header += "---"
# add autogenerated links to whitelist
......@@ -164,6 +176,9 @@ for folder in cardDirs:
whiteList += "/?" + shortcut + "\n"
whiteList += "/cards/" +shortcut + "\n"
whiteList += "/" + folder + "/cards/" + shortcut + "\n"
if "handbook-annexes" in permalink or "handbook-additional" in permalink:
whiteList += " - /cards/" + root_handbook(shortcut) + "\n"
whiteList += " - /" + folder + "/cards/" + root_handbook(shortcut) + "\n"
# add the header properly speaking
line_prepender(fileName, header)
......@@ -171,7 +186,11 @@ for folder in cardDirs:
# open file and get the title after the header
count = 0
title = ""
bp = 9
if "handbook-annexes" in permalink or "handbook-additional" in permalink:
bp = 11
else:
bp = 9
with open(fileName, 'r') as f:
for line in f:
count += 1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment