Support pages inside folders
This commit is contained in:
parent
f81271097c
commit
87bace72a1
@ -86,7 +86,7 @@ def generateFooter(lines):
|
|||||||
|
|
||||||
#parse markdown
|
#parse markdown
|
||||||
if not rawhtml:
|
if not rawhtml:
|
||||||
footer = footer.li(HTML(parseMarkdown(footer, line)))
|
footer = footer.li(HTML(parseMarkdown(line)))
|
||||||
|
|
||||||
def parseRawHTML(doc, line, htmlstring, rawhtml, id, maxlines):
|
def parseRawHTML(doc, line, htmlstring, rawhtml, id, maxlines):
|
||||||
|
|
||||||
@ -112,13 +112,13 @@ def parseRawHTML(doc, line, htmlstring, rawhtml, id, maxlines):
|
|||||||
|
|
||||||
return rawhtml, doc, htmlstring
|
return rawhtml, doc, htmlstring
|
||||||
|
|
||||||
def parseMarkdown(doc, line):
|
def parseMarkdown(line):
|
||||||
|
|
||||||
#do not allow HTML in markdown
|
#do not allow HTML in markdown
|
||||||
line = html.escape(line.strip())
|
line = html.escape(line.strip())
|
||||||
return markdown.markdown(line)
|
return markdown.markdown(line)
|
||||||
|
|
||||||
def generateLines(title, lines):
|
def generateLines(title, lines, path):
|
||||||
title = title.replace(".page", "")
|
title = title.replace(".page", "")
|
||||||
doc = Document(title, lang="en")
|
doc = Document(title, lang="en")
|
||||||
rawhtml = False
|
rawhtml = False
|
||||||
@ -130,17 +130,20 @@ def generateLines(title, lines):
|
|||||||
|
|
||||||
#parse markdown
|
#parse markdown
|
||||||
if not rawhtml:
|
if not rawhtml:
|
||||||
doc = doc(HTML(parseMarkdown(doc, line)))
|
doc = doc(HTML(parseMarkdown(line)))
|
||||||
|
|
||||||
generatePage(title, doc)
|
generatePage(title, doc, path)
|
||||||
|
|
||||||
def generatePage(title, doc):
|
def generatePage(title, doc, path):
|
||||||
global pages
|
global pages
|
||||||
global titles
|
global titles
|
||||||
|
global paths
|
||||||
if 'pages' not in globals():
|
if 'pages' not in globals():
|
||||||
pages = []
|
pages = []
|
||||||
if 'titles' not in globals():
|
if 'titles' not in globals():
|
||||||
titles = []
|
titles = []
|
||||||
|
if 'paths' not in globals():
|
||||||
|
paths = []
|
||||||
|
|
||||||
navbarfile = Path("./").parent.joinpath('navbar')
|
navbarfile = Path("./").parent.joinpath('navbar')
|
||||||
|
|
||||||
@ -161,10 +164,12 @@ def generatePage(title, doc):
|
|||||||
pages.append(str(doc))
|
pages.append(str(doc))
|
||||||
|
|
||||||
titles.append(title)
|
titles.append(title)
|
||||||
|
paths.append(path)
|
||||||
|
|
||||||
def writePages():
|
def writePages():
|
||||||
global pages
|
global pages
|
||||||
global titles
|
global titles
|
||||||
|
global paths
|
||||||
if 'pages' not in globals():
|
if 'pages' not in globals():
|
||||||
print("Error: no page files found")
|
print("Error: no page files found")
|
||||||
exit()
|
exit()
|
||||||
@ -184,8 +189,9 @@ def writePages():
|
|||||||
foldername = titles[id].replace(" ", "-").lower()
|
foldername = titles[id].replace(" ", "-").lower()
|
||||||
|
|
||||||
outputpath = Path("./").parent.joinpath("website-output")
|
outputpath = Path("./").parent.joinpath("website-output")
|
||||||
|
pageoutput = outputpath.joinpath(paths[id])
|
||||||
|
|
||||||
dirpath = outputpath.joinpath(foldername)
|
dirpath = pageoutput.joinpath(foldername)
|
||||||
|
|
||||||
dirpath.mkdir(parents=True, exist_ok=True)
|
dirpath.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
@ -224,6 +230,14 @@ def writePages():
|
|||||||
shutil.rmtree(folder)
|
shutil.rmtree(folder)
|
||||||
else:
|
else:
|
||||||
shutil.move(str(folder), newpath)
|
shutil.move(str(folder), newpath)
|
||||||
|
def findPages(dir):
|
||||||
|
for file in dir.iterdir():
|
||||||
|
if file.is_file():
|
||||||
|
if file.suffix == ".page":
|
||||||
|
with file.open('r') as page:
|
||||||
|
generateLines(file.stem, page.readlines(), dir)
|
||||||
|
elif file.stem != "resources" and file.stem != "website-output":
|
||||||
|
findPages(file)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
@ -239,15 +253,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
print("No 'footer' file found, there will be no footer.")
|
print("No 'footer' file found, there will be no footer.")
|
||||||
|
|
||||||
pagescount = 0
|
findPages(Path("./").parent)
|
||||||
|
|
||||||
for file in Path("./").parent.iterdir():
|
|
||||||
if file.is_file():
|
|
||||||
if file.suffix == ".page":
|
|
||||||
pagescount += 1
|
|
||||||
with file.open('r') as page:
|
|
||||||
generateLines(file.stem, page.readlines())
|
|
||||||
print("Found " + str(pagescount) + " pages")
|
|
||||||
|
|
||||||
#write all pages to files
|
#write all pages to files
|
||||||
writePages()
|
writePages()
|
||||||
|
Loading…
Reference in New Issue
Block a user