Use 2 spaces instead of tab

This commit is contained in:
Govindas 2022-01-21 13:09:43 +02:00
parent 09acb1a9fc
commit acf1a5a097
1 changed files with 32 additions and 33 deletions

View File

@ -6,48 +6,47 @@ from shutil import rmtree
homepage = "Home" homepage = "Home"
try: try:
os.mkdir("./website-output") os.mkdir("./website-output")
except FileExistsError: except FileExistsError:
print("Output directory already exists, let's clean it!") print("Output directory already exists, let's clean it!")
#deleting contents of folder without deleting the folder, to increase compatibility with various systems #deleting contents of folder without deleting the folder, to increase compatibility with various systems
for root, dirs, files in os.walk('./website-output'): for root, dirs, files in os.walk('./website-output'):
for f in files: for f in files:
os.unlink(os.path.join(root, f)) os.unlink(os.path.join(root, f))
for d in dirs: for d in dirs:
rmtree(os.path.join(root, d)) rmtree(os.path.join(root, d))
#generate navigation bar #generate navigation bar
navbarfound = False navbarfound = False
if os.path.exists("./navbar"): if os.path.exists("./navbar"):
with open("./navbar", 'r') as navbarfile: with open("./navbar", 'r') as navbarfile:
navbarfound = True navbarfound = True
navbar = "" navbar = ""
for line in navbarfile.readlines(): for line in navbarfile.readlines():
split = line.strip().split(";", 1) split = line.strip().split(";", 1)
navbar = navbar + "<li><a href='" + split[1] + "'>" + split[0] + "</a></li>" navbar = navbar + "<li><a href='" + split[1] + "'>" + split[0] + "</a></li>"
print(navbar)
else: else:
print("No 'navbar' file found, there will be no navigation bar.") print("No 'navbar' file found, there will be no navigation bar.")
#generate pages #generate pages
for file in os.listdir("./"): for file in os.listdir("./"):
if file.endswith(".page"): if file.endswith(".page"):
with open(file, 'r') as page: with open(file, 'r') as page:
pagetitle = os.path.basename(file).replace(".page", "") pagetitle = os.path.basename(file).replace(".page", "")
doc = Document(pagetitle, lang="en") doc = Document(pagetitle, lang="en")
for line in page.readlines(): for line in page.readlines():
doc.p(line.strip()) doc.p(line.strip())
#creates ./website-output/pagetitle/index.html file if it is not homepage #creates ./website-output/pagetitle/index.html file if it is not homepage
if pagetitle == homepage: if pagetitle == homepage:
foldername = "" foldername = ""
else: else:
foldername = "/" + pagetitle.replace(" ", "-").lower() foldername = "/" + pagetitle.replace(" ", "-").lower()
os.mkdir("./website-output" + foldername) os.mkdir("./website-output" + foldername)
with open("./website-output" + foldername + "/index.html", 'w') as newpage: with open("./website-output" + foldername + "/index.html", 'w') as newpage:
if navbarfound: if navbarfound:
newpage.write("<ul>" + navbar + "</ul>" + str(doc)) newpage.write("<ul>" + navbar + "</ul>" + str(doc))
else: else:
newpage.write(str(doc)) newpage.write(str(doc))