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 markdown
|
||||||
import html
|
import html
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def generateNavigationBar(lines):
|
def generateNavigationBar(lines):
|
||||||
global navbar
|
global navbar
|
||||||
navbar = E
|
navbar = E
|
||||||
@ -19,6 +17,7 @@ def generateNavigationBar(lines):
|
|||||||
#parse markdown
|
#parse markdown
|
||||||
if not rawhtml:
|
if not rawhtml:
|
||||||
navbar = navbar.li(HTML(parseMarkdown(navbar, line)))
|
navbar = navbar.li(HTML(parseMarkdown(navbar, line)))
|
||||||
|
print(str(navbar))
|
||||||
#title, link = line.strip().split(";", 1)
|
#title, link = line.strip().split(";", 1)
|
||||||
#navbar = navbar.li(HTML("<a href='" + link + "'>" + title + "</a>"))
|
#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):
|
def parseMarkdown(doc, line):
|
||||||
line = html.escape(line.strip())
|
line = html.escape(line.strip())
|
||||||
return doc(HTML(markdown.markdown(line)))
|
return markdown.markdown(line)
|
||||||
|
|
||||||
def generateLines(title, lines):
|
def generateLines(title, lines):
|
||||||
title = title.replace(".page", "")
|
title = title.replace(".page", "")
|
||||||
@ -61,7 +60,7 @@ def generateLines(title, lines):
|
|||||||
|
|
||||||
#parse markdown
|
#parse markdown
|
||||||
if not rawhtml:
|
if not rawhtml:
|
||||||
doc = parseMarkdown(doc, line)
|
doc = doc(HTML(parseMarkdown(doc, line)))
|
||||||
|
|
||||||
generatePage(title, doc)
|
generatePage(title, doc)
|
||||||
|
|
||||||
@ -69,6 +68,24 @@ def generatePage(title, doc):
|
|||||||
#creates ./website-output/pagetitle/index.html file if it is not homepage
|
#creates ./website-output/pagetitle/index.html file if it is not homepage
|
||||||
foldername = ""
|
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:
|
if title != homepage:
|
||||||
foldername = "/" + title.replace(" ", "-").lower()
|
foldername = "/" + title.replace(" ", "-").lower()
|
||||||
os.mkdir("./website-output" + foldername)
|
os.mkdir("./website-output" + foldername)
|
||||||
@ -79,24 +96,13 @@ def generatePage(title, doc):
|
|||||||
else:
|
else:
|
||||||
newpage.write(str(doc))
|
newpage.write(str(doc))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
#if homepage is at Home.page, set homepage to "Home"
|
#if homepage is at Home.page, set homepage to "Home"
|
||||||
|
global outputexists
|
||||||
|
outputexists = False
|
||||||
global homepage
|
global homepage
|
||||||
homepage = "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))
|
|
||||||
|
|
||||||
if os.path.exists("./navbar"):
|
if os.path.exists("./navbar"):
|
||||||
with open("./navbar", 'r') as navbarfile:
|
with open("./navbar", 'r') as navbarfile:
|
||||||
generateNavigationBar(navbarfile.readlines())
|
generateNavigationBar(navbarfile.readlines())
|
||||||
|
Loading…
Reference in New Issue
Block a user