Use main()

This commit is contained in:
Govindas 2022-01-24 18:49:02 +02:00
parent 3f7e90fd46
commit 95afcd1e1b
2 changed files with 34 additions and 26 deletions

View File

@ -6,4 +6,4 @@ Another markdown line
<a href=/test>**Another markdown line 2**</a> <a href=/test>**Another markdown line 2**</a>
> >
<p><i>**HTML Italics test 1** <p><i>**HTML Italics test 1**
<p><i>HTML Italics test 2 <p><i>[Test link](/about)

View File

@ -4,20 +4,7 @@ from shutil import rmtree
import markdown import markdown
import html import html
#if homepage is at Home.page, set homepage to "Home"
homepage = "Home"
try:
os.mkdir("./website-output")
except FileExistsError:
print("Output directory already exists, let's clean it!")
#deleting contents of folder without deleting the folder, to increase compatibility with various systems
for root, dirs, files in os.walk('./website-output'):
for f in files:
os.unlink(os.path.join(root, f))
for d in dirs:
rmtree(os.path.join(root, d))
def generateNavigationBar(lines): def generateNavigationBar(lines):
global navbar global navbar
@ -84,16 +71,37 @@ def generatePage(title, doc):
else: else:
newpage.write(str(doc)) newpage.write(str(doc))
if os.path.exists("./navbar"):
with open("./navbar", 'r') as navbarfile:
generateNavigationBar(navbarfile.readlines())
else:
print("No 'navbar' file found, there will be no navigation bar.")
pagescount = 0 def main():
for file in os.listdir("./"): #if homepage is at Home.page, set homepage to "Home"
if file.endswith(".page"): global homepage
with open(file, 'r') as page: homepage = "Home"
generateLines(os.path.basename(file), page.readlines())
pagescount += 1 try:
print("Generated " + str(pagescount) + " pages") os.mkdir("./website-output")
except FileExistsError:
print("Output directory already exists, let's clean it!")
#deleting contents of folder without deleting the folder, to increase compatibility with various systems
for root, dirs, files in os.walk('./website-output'):
for f in files:
os.unlink(os.path.join(root, f))
for d in dirs:
rmtree(os.path.join(root, d))
if os.path.exists("./navbar"):
with open("./navbar", 'r') as navbarfile:
generateNavigationBar(navbarfile.readlines())
else:
print("No 'navbar' file found, there will be no navigation bar.")
pagescount = 0
for file in os.listdir("./"):
if file.endswith(".page"):
with open(file, 'r') as page:
generateLines(os.path.basename(file), page.readlines())
pagescount += 1
print("Generated " + str(pagescount) + " pages")
if __name__ == "__main__":
main()