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

Merge branch 'intro-legacy-from' into 'develop'

changes to index generator to include legacy links

See merge request R3/howto-cards!323
parents 6d9a470c cd8dc864
No related branches found
No related tags found
No related merge requests found
......@@ -42,16 +42,36 @@ def build_section_start(title, shortcut):
def build_section_end():
return "\t\t</ul>\n\t</div>"
def remove_header(localroot, root, filename, n=5):
nfirstlines = []
def save_legacy_from(localroot, root, filename):
legacy_from = []
os.chdir(root)
count = 0
legacy_from_flag = False
with open(filename, 'r') as f:
for line in f:
count += 1
# check for the start of the section
if line[0:12] == "legacy_from:":
legacy_from_flag = True
#cwd = os.getcwd()
# append lines from the legacy section
if legacy_from_flag and line[0:12]:
legacy_from.append(line)
# check for the end of the header
if legacy_from_flag and line[0:3] == "---":
legacy_from_flag = False
# change back to the local root
os.chdir(localroot)
#print("Local root folder:" + os.getcwd())
return legacy_from
def remove_header(localroot, root, filename):
nfirstlines = []
os.chdir(root)
#print("Local folder:" + os.getcwd())
# count the number of lines
count = 0
......@@ -61,11 +81,12 @@ def remove_header(localroot, root, filename, n=5):
count += 1
# check if the header is actually a header
if (count == 0 or count == n) and line[0:3] == "---":
if count > 1 and line[0:3] == "---":
headerCheck = True
n = count
# remove the header
if count > n and headerCheck:
if headerCheck:
with open(filename) as f, open("tmp"+filename, "w") as out:
for _ in range(n):
nfirstlines.append(next(f))
......@@ -78,7 +99,6 @@ def remove_header(localroot, root, filename, n=5):
# change back to the local root
os.chdir(localroot)
#print("exit folder:" + os.getcwd())
# loop through the entire internal tree
localroot = os.getcwd()
......@@ -137,11 +157,14 @@ for folder in cardDirs:
if file[0] != "_":
print(" > Generating header for: " + fileName)
# save legacy section
legacy_from = save_legacy_from(localroot, root, file)
# remove the previous header
if "handbook-annexes" in fileName or "handbook-additional" in fileName:
remove_header(localroot, root, file, 10)
remove_header(localroot, root, file)
else:
remove_header(localroot, root, file, 8)
remove_header(localroot, root, file)
# generate a permalink
permalink = "/" + root + "/"
......@@ -169,7 +192,12 @@ for folder in cardDirs:
header += " - /cards/" + root_handbook(shortcut) + "\n"
header += " - /" + folder + "/cards/" + root_handbook(shortcut) + "\n"
header += "---"
# include the legacy section
if len(legacy_from) > 0:
for item in legacy_from:
header += str(item)
else:
header += "---"
# add autogenerated links to whitelist
whiteList += permalink + "\n"
......
......@@ -107,6 +107,7 @@ order: -1
<li><a href="{{ 'external/lab/maintenance_of_cold_traps' | relative_url }}">Maintenance of cold traps </a></li>
<li><a href="{{ 'external/lab/personal-alert-safety-system' | relative_url }}">Personal alert safety system (PASS)</a></li>
<li><a href="{{ 'external/lab/quarks-general' | relative_url }}">Quarks - General information</a></li>
<li><a href="{{ 'external/lab/utilization-of-autoclaves' | relative_url }}">Utilization of autoclaves</a></li>
<li><a href="{{ 'external/lab/utilization-of-balances' | relative_url }}">Utilization of balances</a></li>
<li><a href="{{ 'external/lab/utilization-of-pH-meter' | relative_url }}">Utilization of pH meter</a></li>
......
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