Use pathlib more wisely
This commit is contained in:
parent
5d27050293
commit
fcb4c1534a
@ -98,9 +98,10 @@ def writePages(homepage):
|
|||||||
if titles[id] != homepage:
|
if titles[id] != homepage:
|
||||||
foldername = "/" + titles[id].replace(" ", "-").lower()
|
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():
|
if filepath.exists():
|
||||||
with filepath.open('r') as newpage:
|
with filepath.open('r') as newpage:
|
||||||
@ -117,7 +118,7 @@ def main():
|
|||||||
#if homepage is at Home.page, set homepage to "Home"
|
#if homepage is at Home.page, set homepage to "Home"
|
||||||
homepage = "Home"
|
homepage = "Home"
|
||||||
|
|
||||||
navbarfile = Path("./navbar")
|
navbarfile = Path(__file__).parent.joinpath('navbar')
|
||||||
|
|
||||||
if navbarfile.exists():
|
if navbarfile.exists():
|
||||||
with navbarfile.open('r') as navbarfile:
|
with navbarfile.open('r') as navbarfile:
|
||||||
@ -128,11 +129,12 @@ def main():
|
|||||||
pagescount = 0
|
pagescount = 0
|
||||||
|
|
||||||
for file in Path(__file__).parent.iterdir():
|
for file in Path(__file__).parent.iterdir():
|
||||||
|
#TODO get file name only
|
||||||
if file.is_file():
|
if file.is_file():
|
||||||
if str(file).endswith(".page"):
|
if file.suffix == ".page":
|
||||||
pagescount += 1
|
pagescount += 1
|
||||||
with file.open('r') as page:
|
with file.open('r') as page:
|
||||||
generateLines(str(file), page.readlines())
|
generateLines(str(file.stem), page.readlines())
|
||||||
print("Found " + str(pagescount) + " pages")
|
print("Found " + str(pagescount) + " pages")
|
||||||
|
|
||||||
#write all pages to files
|
#write all pages to files
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
Home;/
|
[Home](/)
|
||||||
About;/about
|
[About](/about)
|
||||||
|
Loading…
Reference in New Issue
Block a user