From fcb4c1534af8bcd2d6551a5a87c53c8afcfbe25f Mon Sep 17 00:00:00 2001 From: Govindas Date: Thu, 27 Jan 2022 13:02:35 +0200 Subject: [PATCH] Use pathlib more wisely --- gsitegen/generate.py | 12 +++++++----- gsitegen/navbar | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/gsitegen/generate.py b/gsitegen/generate.py index bd88115..e076737 100644 --- a/gsitegen/generate.py +++ b/gsitegen/generate.py @@ -98,9 +98,10 @@ def writePages(homepage): if titles[id] != homepage: foldername = "/" + titles[id].replace(" ", "-").lower() - Path("./website-output" + foldername).mkdir(parents=True, exist_ok=True) + dirpath = Path(__file__).parent.joinpath("website-output" + foldername) + dirpath.mkdir(parents=True, exist_ok=True) - filepath = Path("./website-output" + foldername + "/index.html") + filepath = dirpath.joinpath("index.html") if filepath.exists(): with filepath.open('r') as newpage: @@ -117,7 +118,7 @@ def main(): #if homepage is at Home.page, set homepage to "Home" homepage = "Home" - navbarfile = Path("./navbar") + navbarfile = Path(__file__).parent.joinpath('navbar') if navbarfile.exists(): with navbarfile.open('r') as navbarfile: @@ -128,11 +129,12 @@ def main(): pagescount = 0 for file in Path(__file__).parent.iterdir(): + #TODO get file name only if file.is_file(): - if str(file).endswith(".page"): + if file.suffix == ".page": pagescount += 1 with file.open('r') as page: - generateLines(str(file), page.readlines()) + generateLines(str(file.stem), page.readlines()) print("Found " + str(pagescount) + " pages") #write all pages to files diff --git a/gsitegen/navbar b/gsitegen/navbar index e1de320..5498e0e 100644 --- a/gsitegen/navbar +++ b/gsitegen/navbar @@ -1,2 +1,2 @@ -Home;/ -About;/about +[Home](/) +[About](/about)