Functions
This commit is contained in:
parent
e5583310cd
commit
c5cf7e970d
43
generate.py
43
generate.py
@ -17,7 +17,6 @@ except FileExistsError:
|
|||||||
for d in dirs:
|
for d in dirs:
|
||||||
rmtree(os.path.join(root, d))
|
rmtree(os.path.join(root, d))
|
||||||
|
|
||||||
#generate navigation bar
|
|
||||||
def generateNavigationBar(lines):
|
def generateNavigationBar(lines):
|
||||||
global navbar
|
global navbar
|
||||||
navbar = E
|
navbar = E
|
||||||
@ -25,29 +24,37 @@ def generateNavigationBar(lines):
|
|||||||
split = line.strip().split(";", 1)
|
split = line.strip().split(";", 1)
|
||||||
navbar = navbar.li(HTML("<a href='" + split[1] + "'>" + split[0] + "</a>"))
|
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"):
|
if os.path.exists("./navbar"):
|
||||||
with open("./navbar", 'r') as navbarfile:
|
with open("./navbar", 'r') as navbarfile:
|
||||||
generateNavigationBar(navbarfile.readlines())
|
generateNavigationBar(navbarfile.readlines())
|
||||||
else:
|
else:
|
||||||
print("No 'navbar' file found, there will be no navigation bar.")
|
print("No 'navbar' file found, there will be no navigation bar.")
|
||||||
|
|
||||||
#generate pages
|
|
||||||
for file in os.listdir("./"):
|
for file in os.listdir("./"):
|
||||||
if file.endswith(".page"):
|
if file.endswith(".page"):
|
||||||
with open(file, 'r') as page:
|
with open(file, 'r') as page:
|
||||||
pagetitle = os.path.basename(file).replace(".page", "")
|
generateLines(os.path.basename(file), page.readlines())
|
||||||
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))
|
|
||||||
|
Loading…
Reference in New Issue
Block a user