More code cleanup

This commit is contained in:
Govindas 2022-01-26 12:36:59 +02:00
parent 2d6058d451
commit 253851b871
2 changed files with 12 additions and 13 deletions

View File

@ -1,5 +1,5 @@
# Welcome!
This is the homepage of our website....
This is the homepage of our website.....
>
<b>HTML Hello</b>
Another markdown line

View File

@ -20,6 +20,7 @@ def generateNavigationBar(lines):
navbar = navbar.li(HTML(parseMarkdown(navbar, line)))
def parseRawHTML(doc, line, htmlstring, rawhtml, id, maxlines):
#raw html start
if line.strip() == ">":
rawhtml = True
@ -43,6 +44,7 @@ def parseRawHTML(doc, line, htmlstring, rawhtml, id, maxlines):
return rawhtml, doc, htmlstring
def parseMarkdown(doc, line):
#do not allow HTML in markdown
line = html.escape(line.strip())
return markdown.markdown(line)
@ -74,10 +76,9 @@ def generatePage(title, doc):
if 'navbar' in globals():
pages.append(str(E.ul(navbar)) + str(doc))
titles.append(title)
else:
pages.append(str(doc))
titles.append(title)
titles.append(title)
def writePages(homepage):
global pages
@ -97,6 +98,7 @@ def writePages(homepage):
for id, page in enumerate(pages):
foldername = ""
#creates ./website-output/pagetitle/index.html file if it is not homepage
if titles[id] != homepage:
foldername = "/" + titles[id].replace(" ", "-").lower()
@ -106,23 +108,19 @@ def writePages(homepage):
os.mkdir("./website-output" + foldername)
except FileExistsError:
pass
changed = True
filepath = Path("./website-output" + foldername + "/index.html")
if filepath.exists():
with open("./website-output" + foldername + "/index.html", 'r') as newpage:
if newpage.read() == page:
changed = False
if changed:
with open("./website-output" + foldername + "/index.html", 'w') as newpage:
newpage.write(page)
print("Written changed page: " + titles[id])
else:
print("Page not changed: " + titles[id])
print("Page not changed: " + titles[id])
continue
with open("./website-output" + foldername + "/index.html", 'w') as newpage:
newpage.write(page)
print("Written changed page: " + titles[id])
def main():
#if homepage is at Home.page, set homepage to "Home"
homepage = "Home"
@ -141,6 +139,7 @@ def main():
generateLines(os.path.basename(file), page.readlines())
print("Found " + str(pagescount) + " pages")
#write all pages to files
writePages(homepage)
if __name__ == "__main__":