More pathlib usage & code cleanup
This commit is contained in:
parent
253851b871
commit
78817f4467
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
||||
website-output
|
||||
__pycache__
|
||||
coverage.xml
|
||||
/gsitegen/*.page
|
||||
|
@ -5,6 +5,7 @@ import markdown
|
||||
import html
|
||||
from pathlib import Path
|
||||
|
||||
#TODO re-think navigation bar. Think of way to add option to display navigation bar entry differently if you're currently on that page.
|
||||
def generateNavigationBar(lines):
|
||||
global navbar
|
||||
navbar = E
|
||||
@ -108,14 +109,16 @@ def writePages(homepage):
|
||||
os.mkdir("./website-output" + foldername)
|
||||
except FileExistsError:
|
||||
pass
|
||||
filepath = Path("./website-output" + foldername + "/index.html")
|
||||
|
||||
if filepath.exists():
|
||||
with open("./website-output" + foldername + "/index.html", 'r') as newpage:
|
||||
filepath = "./website-output" + foldername + "/index.html"
|
||||
|
||||
if Path(filepath).exists():
|
||||
with open(filepath, 'r') as newpage:
|
||||
if newpage.read() == page:
|
||||
print("Page not changed: " + titles[id])
|
||||
continue
|
||||
with open("./website-output" + foldername + "/index.html", 'w') as newpage:
|
||||
|
||||
with open(filepath, 'w') as newpage:
|
||||
newpage.write(page)
|
||||
print("Written changed page: " + titles[id])
|
||||
|
||||
@ -124,13 +127,12 @@ def main():
|
||||
#if homepage is at Home.page, set homepage to "Home"
|
||||
homepage = "Home"
|
||||
|
||||
if os.path.exists("./navbar"):
|
||||
if Path("./navbar").exists():
|
||||
with open("./navbar", 'r') as navbarfile:
|
||||
generateNavigationBar(navbarfile.readlines())
|
||||
else:
|
||||
print("No 'navbar' file found, there will be no navigation bar.")
|
||||
|
||||
#count total amount of pages first
|
||||
pagescount = 0
|
||||
for file in os.listdir("./"):
|
||||
if file.endswith(".page"):
|
||||
|
Loading…
Reference in New Issue
Block a user