From 0673f6a79052d50244fa080f13d7d8f75755bbfb Mon Sep 17 00:00:00 2001 From: Govindas Date: Sat, 22 Jan 2022 11:54:31 +0200 Subject: [PATCH] Progress on making code cleaner --- generate.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/generate.py b/generate.py index d7b99a9..ba7e5d8 100644 --- a/generate.py +++ b/generate.py @@ -18,17 +18,17 @@ except FileExistsError: rmtree(os.path.join(root, d)) #generate navigation bar -navbarfound = False +def generateNavigationBar(lines): + global navbar + navbar = E + for line in lines: + split = line.strip().split(";", 1) + navbar.li(HTML("" + split[0])) + if os.path.exists("./navbar"): with open("./navbar", 'r') as navbarfile: - navbarfound = True - navbar = E - for line in navbarfile.readlines(): - split = line.strip().split(";", 1) - navbar = navbar.li(HTML("" + split[0])) - -#checking false instead of else to be more sure -if navbarfound == False: + generateNavigationBar(navbarfile.readlines()) +else: print("No 'navbar' file found, there will be no navigation bar.") #generate pages @@ -41,13 +41,13 @@ for file in os.listdir("./"): doc.p(line.strip()) #creates ./website-output/pagetitle/index.html file if it is not homepage - foldername = "" - if pagetitle =! homepage: + foldername = "" + if pagetitle != homepage: foldername = "/" + pagetitle.replace(" ", "-").lower() os.mkdir("./website-output" + foldername) with open("./website-output" + foldername + "/index.html", 'w') as newpage: - if navbarfound: + if 'navbar' in globals(): newpage.write(str(E.ul(navbar))) else: newpage.write(str(doc))