diff --git a/gsitegen/generate.py b/gsitegen/generate.py index 3075196..089a9d8 100644 --- a/gsitegen/generate.py +++ b/gsitegen/generate.py @@ -86,7 +86,7 @@ def generateFooter(lines): #parse markdown if not rawhtml: - footer = footer.li(HTML(parseMarkdown(footer, line))) + footer = footer.li(HTML(parseMarkdown(line))) def parseRawHTML(doc, line, htmlstring, rawhtml, id, maxlines): @@ -112,13 +112,13 @@ def parseRawHTML(doc, line, htmlstring, rawhtml, id, maxlines): return rawhtml, doc, htmlstring -def parseMarkdown(doc, line): +def parseMarkdown(line): #do not allow HTML in markdown line = html.escape(line.strip()) return markdown.markdown(line) -def generateLines(title, lines): +def generateLines(title, lines, path): title = title.replace(".page", "") doc = Document(title, lang="en") rawhtml = False @@ -130,17 +130,20 @@ def generateLines(title, lines): #parse markdown if not rawhtml: - doc = doc(HTML(parseMarkdown(doc, line))) + doc = doc(HTML(parseMarkdown(line))) - generatePage(title, doc) + generatePage(title, doc, path) -def generatePage(title, doc): +def generatePage(title, doc, path): global pages global titles + global paths if 'pages' not in globals(): pages = [] if 'titles' not in globals(): titles = [] + if 'paths' not in globals(): + paths = [] navbarfile = Path("./").parent.joinpath('navbar') @@ -161,10 +164,12 @@ def generatePage(title, doc): pages.append(str(doc)) titles.append(title) + paths.append(path) def writePages(): global pages global titles + global paths if 'pages' not in globals(): print("Error: no page files found") exit() @@ -184,8 +189,9 @@ def writePages(): foldername = titles[id].replace(" ", "-").lower() outputpath = Path("./").parent.joinpath("website-output") + pageoutput = outputpath.joinpath(paths[id]) - dirpath = outputpath.joinpath(foldername) + dirpath = pageoutput.joinpath(foldername) dirpath.mkdir(parents=True, exist_ok=True) @@ -224,6 +230,14 @@ def writePages(): shutil.rmtree(folder) else: shutil.move(str(folder), newpath) +def findPages(dir): + for file in dir.iterdir(): + if file.is_file(): + if file.suffix == ".page": + with file.open('r') as page: + generateLines(file.stem, page.readlines(), dir) + elif file.stem != "resources" and file.stem != "website-output": + findPages(file) def main(): @@ -239,15 +253,7 @@ def main(): else: print("No 'footer' file found, there will be no footer.") - pagescount = 0 - - for file in Path("./").parent.iterdir(): - if file.is_file(): - if file.suffix == ".page": - pagescount += 1 - with file.open('r') as page: - generateLines(file.stem, page.readlines()) - print("Found " + str(pagescount) + " pages") + findPages(Path("./").parent) #write all pages to files writePages()