Small code reduction

This commit is contained in:
Govindas 2022-01-26 12:08:19 +02:00
parent 08f12551c5
commit 2d6058d451
1 changed files with 5 additions and 7 deletions

View File

@ -66,11 +66,12 @@ def generateLines(title, lines):
def generatePage(title, doc): def generatePage(title, doc):
global pages global pages
global titles global titles
global pagescount
if 'pages' not in globals(): if 'pages' not in globals():
pages = [] pages = []
if 'titles' not in globals(): if 'titles' not in globals():
titles = [] titles = []
if 'navbar' in globals(): if 'navbar' in globals():
pages.append(str(E.ul(navbar)) + str(doc)) pages.append(str(E.ul(navbar)) + str(doc))
titles.append(title) titles.append(title)
@ -86,7 +87,6 @@ def writePages(homepage):
os.mkdir("./website-output") os.mkdir("./website-output")
except FileExistsError: except FileExistsError:
pass pass
print("Output directory already exists, let's clean it!")
#TODO only delete files that aren't present in newest site generation #TODO only delete files that aren't present in newest site generation
#deleting contents of folder without deleting the folder, to increase compatibility with various systems #deleting contents of folder without deleting the folder, to increase compatibility with various systems
#for root, dirs, files in os.walk('./website-output'): #for root, dirs, files in os.walk('./website-output'):
@ -107,15 +107,13 @@ def writePages(homepage):
except FileExistsError: except FileExistsError:
pass pass
changed = False changed = True
filepath = Path("./website-output" + foldername + "/index.html") filepath = Path("./website-output" + foldername + "/index.html")
if filepath.exists(): if filepath.exists():
with open("./website-output" + foldername + "/index.html", 'r') as newpage: with open("./website-output" + foldername + "/index.html", 'r') as newpage:
if newpage.read() != page: if newpage.read() == page:
changed = True changed = False
else:
changed = True
if changed: if changed:
with open("./website-output" + foldername + "/index.html", 'w') as newpage: with open("./website-output" + foldername + "/index.html", 'w') as newpage: