Gitlab migration complete. If you have any issue please read the FAQ.

Verified Commit 4248b6de authored by Laurent Heirendt's avatar Laurent Heirendt
Browse files

avoid hidden folders

parent 340c51d4
import os, re
folder = "external"
folder = "internal"
def line_prepender(filename, line):
with open(filename, 'r+') as f:
......@@ -58,72 +58,73 @@ index = ""
for d in dirs:
# set the header of the section
index += "\n### " + d.replace("-", " ").capitalize() + "\n"
localIndexArr = ["\n"]
# walk through the folders with all the cards
for root, dirs, files in os.walk(folder+"/"+d):
for file in files:
if file.endswith(".md"):
fileName = os.path.join(root, file)
# ignore subsections (.md files that start with _)
if file[0] != "_":
print(" > Generating header for: " + fileName)
# remove the previous header
remove_header(localroot, root, file, 8)
# generate a permalink
permalink = "/" + root + "/"
# generate the shortcut
shortcut = re.sub(folder, '', root)
# remove the first /
shortcut = shortcut[1:]
# replace the / with a :
shortcut = re.sub('/', ':', shortcut)
# define the header for each card
header = "---\n"
header += "layout: page\n"
header += "permalink: " + permalink + "\n"
header += "shortcut: " + shortcut + "\n"
header += "redirect_from:\n"
header += " - /cards/" + shortcut + "\n"
header += " - /internal/cards/" + shortcut + "\n"
header += "---"
# add the header properly speaking
line_prepender(fileName, header)
# open file and get the title after the header
count = 0
title = ""
with open(fileName, 'r') as f:
for line in f:
count += 1
if count == 9:
title = line
break
# remove first and last chars
title = title.rstrip("\n\r")
title = title[2:]
#index += " * [" + title + "](./" + root + "/" + "\n"
localIndexArr.append("* [" + title + "](./" + root + "/" + ")\n")
# output
print(" + New header added.")
print("-----------------------")
# join all subcategories to the index
localIndexArr.sort()
index += ''.join(localIndexArr)
if d[0] != ".":
# set the header of the section
index += "\n### " + d.replace("-", " ").capitalize() + "\n"
localIndexArr = ["\n"]
# walk through the folders with all the cards
for root, dirs, files in os.walk(folder+"/"+d):
for file in files:
if file.endswith(".md"):
fileName = os.path.join(root, file)
# ignore subsections (.md files that start with _)
if file[0] != "_":
print(" > Generating header for: " + fileName)
# remove the previous header
remove_header(localroot, root, file, 8)
# generate a permalink
permalink = "/" + root + "/"
# generate the shortcut
shortcut = re.sub(folder, '', root)
# remove the first /
shortcut = shortcut[1:]
# replace the / with a :
shortcut = re.sub('/', ':', shortcut)
# define the header for each card
header = "---\n"
header += "layout: page\n"
header += "permalink: " + permalink + "\n"
header += "shortcut: " + shortcut + "\n"
header += "redirect_from:\n"
header += " - /cards/" + shortcut + "\n"
header += " - /internal/cards/" + shortcut + "\n"
header += "---"
# add the header properly speaking
line_prepender(fileName, header)
# open file and get the title after the header
count = 0
title = ""
with open(fileName, 'r') as f:
for line in f:
count += 1
if count == 9:
title = line
break
# remove first and last chars
title = title.rstrip("\n\r")
title = title[2:]
#index += " * [" + title + "](./" + root + "/" + "\n"
localIndexArr.append("* [" + title + "](./" + root + "/" + ")\n")
# output
print(" + New header added.")
print("-----------------------")
# join all subcategories to the index
localIndexArr.sort()
index += ''.join(localIndexArr)
# output the index
#print(index)
......
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