From 253851b871715634800d5ade99f182eed05ea14d Mon Sep 17 00:00:00 2001 From: Govindas Date: Wed, 26 Jan 2022 12:36:59 +0200 Subject: [PATCH] More code cleanup --- gsitegen/Home.page | 2 +- gsitegen/generate.py | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/gsitegen/Home.page b/gsitegen/Home.page index a40856f..758a5f4 100644 --- a/gsitegen/Home.page +++ b/gsitegen/Home.page @@ -1,5 +1,5 @@ # Welcome! -This is the homepage of our website.... +This is the homepage of our website..... > HTML Hello Another markdown line diff --git a/gsitegen/generate.py b/gsitegen/generate.py index a711dfe..c6e13c7 100644 --- a/gsitegen/generate.py +++ b/gsitegen/generate.py @@ -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__":