Functions

This commit is contained in:
Govindas 2022-01-22 16:06:25 +02:00
parent e5583310cd
commit c5cf7e970d

View File

@ -17,7 +17,6 @@ except FileExistsError:
for d in dirs:
rmtree(os.path.join(root, d))
#generate navigation bar
def generateNavigationBar(lines):
global navbar
navbar = E
@ -25,29 +24,37 @@ def generateNavigationBar(lines):
split = line.strip().split(";", 1)
navbar = navbar.li(HTML("<a href='" + split[1] + "'>" + split[0] + "</a>"))
def generateLines(title, lines):
global document
title = title.replace(".page", "")
document = Document(title, lang="en")
for line in lines:
document.p(line.strip())
generatePage(title)
def generatePage(title):
#creates ./website-output/pagetitle/index.html file if it is not homepage
foldername = ""
if title != homepage:
foldername = "/" + title.replace(" ", "-").lower()
os.mkdir("./website-output" + foldername)
with open("./website-output" + foldername + "/index.html", 'w') as newpage:
if 'navbar' in globals():
newpage.write(str(E.ul(navbar).join(document)))
else:
newpage.write(str(document))
if os.path.exists("./navbar"):
with open("./navbar", 'r') as navbarfile:
generateNavigationBar(navbarfile.readlines())
else:
print("No 'navbar' file found, there will be no navigation bar.")
#generate pages
for file in os.listdir("./"):
if file.endswith(".page"):
with open(file, 'r') as page:
pagetitle = os.path.basename(file).replace(".page", "")
doc = Document(pagetitle, lang="en")
for line in page.readlines():
doc.p(line.strip())
#creates ./website-output/pagetitle/index.html file if it is not homepage
foldername = ""
if pagetitle != homepage:
foldername = "/" + pagetitle.replace(" ", "-").lower()
os.mkdir("./website-output" + foldername)
print(foldername)
with open("./website-output" + foldername + "/index.html", 'w') as newpage:
if 'navbar' in globals():
newpage.write(str(E.ul(navbar)) + str(doc))
else:
newpage.write(str(doc))
generateLines(os.path.basename(file), page.readlines())