diff --git a/.ci/generateIndex.py b/.ci/generateIndex.py
index 15e4bf7ab0ed7391c50ae646c7a7a6e4af66c55b..1175daef65c8146421a6b670db09742bac9ae67b 100644
--- a/.ci/generateIndex.py
+++ b/.ci/generateIndex.py
@@ -42,7 +42,7 @@ 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):
+def remove_header(localroot, root, filename):
     nfirstlines = []
 
     #cwd = os.getcwd()
@@ -61,8 +61,9 @@ 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:
@@ -139,9 +140,9 @@ for folder in cardDirs:
 
                                 # 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 + "/"