From faacb4cfdef6f347a8b3babc62d7033322fa7cff Mon Sep 17 00:00:00 2001 From: Govindas Date: Tue, 25 Jan 2022 16:45:27 +0200 Subject: [PATCH] Further navigation improvements, start of remaking compiling process --- gsitegen/generate.py | 54 ++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/gsitegen/generate.py b/gsitegen/generate.py index a0609a2..a48534d 100644 --- a/gsitegen/generate.py +++ b/gsitegen/generate.py @@ -4,8 +4,6 @@ from shutil import rmtree import markdown import html - - def generateNavigationBar(lines): global navbar navbar = E @@ -19,6 +17,7 @@ def generateNavigationBar(lines): #parse markdown if not rawhtml: navbar = navbar.li(HTML(parseMarkdown(navbar, line))) + print(str(navbar)) #title, link = line.strip().split(";", 1) #navbar = navbar.li(HTML("" + title + "")) @@ -47,7 +46,7 @@ def parseRawHTML(doc, line, htmlstring, rawhtml, id, maxlines): def parseMarkdown(doc, line): line = html.escape(line.strip()) - return doc(HTML(markdown.markdown(line))) + return markdown.markdown(line) def generateLines(title, lines): title = title.replace(".page", "") @@ -61,7 +60,7 @@ def generateLines(title, lines): #parse markdown if not rawhtml: - doc = parseMarkdown(doc, line) + doc = doc(HTML(parseMarkdown(doc, line))) generatePage(title, doc) @@ -69,34 +68,41 @@ def generatePage(title, doc): #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) + global outputexists + if not outputexists: + 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: - if 'navbar' in globals(): - newpage.write(str(E.ul(navbar)) + str(doc)) - else: - newpage.write(str(doc)) + #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)) + #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(): #if homepage is at Home.page, set homepage to "Home" + global outputexists + outputexists = False global homepage 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"): with open("./navbar", 'r') as navbarfile: generateNavigationBar(navbarfile.readlines())