Further navigation improvements, start of remaking compiling process
This commit is contained in:
parent
6329d05bfe
commit
faacb4cfde
@ -4,8 +4,6 @@ from shutil import rmtree
|
||||
import markdown
|
||||
import html
|
||||
|
||||
|
||||
|
||||
def generateNavigationBar(lines):
|
||||
global navbar
|
||||
navbar = E
|
||||
@ -19,6 +17,7 @@ def generateNavigationBar(lines):
|
||||
#parse markdown
|
||||
if not rawhtml:
|
||||
navbar = navbar.li(HTML(parseMarkdown(navbar, line)))
|
||||
print(str(navbar))
|
||||
#title, link = line.strip().split(";", 1)
|
||||
#navbar = navbar.li(HTML("<a href='" + link + "'>" + title + "</a>"))
|
||||
|
||||
@ -47,7 +46,7 @@ def parseRawHTML(doc, line, htmlstring, rawhtml, id, maxlines):
|
||||
|
||||
def parseMarkdown(doc, line):
|
||||
line = html.escape(line.strip())
|
||||
return doc(HTML(markdown.markdown(line)))
|
||||
return markdown.markdown(line)
|
||||
|
||||
def generateLines(title, lines):
|
||||
title = title.replace(".page", "")
|
||||
@ -61,7 +60,7 @@ def generateLines(title, lines):
|
||||
|
||||
#parse markdown
|
||||
if not rawhtml:
|
||||
doc = parseMarkdown(doc, line)
|
||||
doc = doc(HTML(parseMarkdown(doc, line)))
|
||||
|
||||
generatePage(title, doc)
|
||||
|
||||
@ -69,6 +68,24 @@ def generatePage(title, doc):
|
||||
#creates ./website-output/pagetitle/index.html file if it is not homepage
|
||||
foldername = ""
|
||||
|
||||
global outputexists
|
||||
if not outputexists:
|
||||
try:
|
||||
os.mkdir("./website-output")
|
||||
outputexists = True
|
||||
except FileExistsError:
|
||||
print("Output directory already exists, let's clean it!")
|
||||
outputexists = True
|
||||
|
||||
#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))
|
||||
|
||||
#not using else to be sure
|
||||
if outputexists:
|
||||
if title != homepage:
|
||||
foldername = "/" + title.replace(" ", "-").lower()
|
||||
os.mkdir("./website-output" + foldername)
|
||||
@ -79,24 +96,13 @@ def generatePage(title, doc):
|
||||
else:
|
||||
newpage.write(str(doc))
|
||||
|
||||
|
||||
def main():
|
||||
#if homepage is at Home.page, set homepage to "Home"
|
||||
global outputexists
|
||||
outputexists = False
|
||||
global homepage
|
||||
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))
|
||||
|
||||
if os.path.exists("./navbar"):
|
||||
with open("./navbar", 'r') as navbarfile:
|
||||
generateNavigationBar(navbarfile.readlines())
|
||||
|
Loading…
Reference in New Issue
Block a user