Further navigation improvements, start of remaking compiling process

This commit is contained in:
Govindas 2022-01-25 16:45:27 +02:00
parent 6329d05bfe
commit faacb4cfde

View File

@ -4,8 +4,6 @@ from shutil import rmtree
import markdown import markdown
import html import html
def generateNavigationBar(lines): def generateNavigationBar(lines):
global navbar global navbar
navbar = E navbar = E
@ -19,6 +17,7 @@ def generateNavigationBar(lines):
#parse markdown #parse markdown
if not rawhtml: if not rawhtml:
navbar = navbar.li(HTML(parseMarkdown(navbar, line))) navbar = navbar.li(HTML(parseMarkdown(navbar, line)))
print(str(navbar))
#title, link = line.strip().split(";", 1) #title, link = line.strip().split(";", 1)
#navbar = navbar.li(HTML("<a href='" + link + "'>" + title + "</a>")) #navbar = navbar.li(HTML("<a href='" + link + "'>" + title + "</a>"))
@ -47,7 +46,7 @@ def parseRawHTML(doc, line, htmlstring, rawhtml, id, maxlines):
def parseMarkdown(doc, line): def parseMarkdown(doc, line):
line = html.escape(line.strip()) line = html.escape(line.strip())
return doc(HTML(markdown.markdown(line))) return markdown.markdown(line)
def generateLines(title, lines): def generateLines(title, lines):
title = title.replace(".page", "") title = title.replace(".page", "")
@ -61,7 +60,7 @@ def generateLines(title, lines):
#parse markdown #parse markdown
if not rawhtml: if not rawhtml:
doc = parseMarkdown(doc, line) doc = doc(HTML(parseMarkdown(doc, line)))
generatePage(title, doc) generatePage(title, doc)
@ -69,34 +68,41 @@ def generatePage(title, doc):
#creates ./website-output/pagetitle/index.html file if it is not homepage #creates ./website-output/pagetitle/index.html file if it is not homepage
foldername = "" foldername = ""
if title != homepage: global outputexists
foldername = "/" + title.replace(" ", "-").lower() if not outputexists:
os.mkdir("./website-output" + foldername) try:
os.mkdir("./website-output")
outputexists = True
except FileExistsError:
print("Output directory already exists, let's clean it!")
outputexists = True
with open("./website-output" + foldername + "/index.html", 'w') as newpage: #deleting contents of folder without deleting the folder, to increase compatibility with various systems
if 'navbar' in globals(): for root, dirs, files in os.walk('./website-output'):
newpage.write(str(E.ul(navbar)) + str(doc)) for f in files:
else: os.unlink(os.path.join(root, f))
newpage.write(str(doc)) for d in dirs:
rmtree(os.path.join(root, d))
#not using else to be sure
if outputexists:
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)) + str(doc))
else:
newpage.write(str(doc))
def main(): def main():
#if homepage is at Home.page, set homepage to "Home" #if homepage is at Home.page, set homepage to "Home"
global outputexists
outputexists = False
global homepage global homepage
homepage = "Home" homepage = "Home"
try:
os.mkdir("./website-output")
except FileExistsError:
print("Output directory already exists, let's clean it!")
#deleting contents of folder without deleting the folder, to increase compatibility with various systems
for root, dirs, files in os.walk('./website-output'):
for f in files:
os.unlink(os.path.join(root, f))
for d in dirs:
rmtree(os.path.join(root, d))
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())