Use pathlib more wisely

This commit is contained in:
Govindas 2022-01-27 13:02:35 +02:00
parent 5d27050293
commit fcb4c1534a
2 changed files with 9 additions and 7 deletions

View File

@ -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

View File

@ -1,2 +1,2 @@
Home;/
About;/about
[Home](/)
[About](/about)