Improve navbar, unfinished dropdown support

This commit is contained in:
Govindas 2022-02-04 19:29:07 +02:00
parent aef5528bb0
commit 6c06865726
2 changed files with 25 additions and 8 deletions

View File

@ -10,6 +10,7 @@ def generateNavigationBar(lines, pagetitle):
navbar = E
rawhtml = False
htmlstring = ""
dropdown = False
for id, line in enumerate(lines):
#parse raw HTML
@ -25,27 +26,38 @@ def generateNavigationBar(lines, pagetitle):
# contents.append(line.split("|"))
#else:
# contents.append(line)
#for entry in contents:
title, link = line.split(";", 1)
if line.strip().endswith("|"):
dropdown = True
line = line.strip()[-1]
dphtml = E
dphtml = dphtml(HTML("<div class='dropdown'><button class 'dropbutton'>Test more</button><div class='dropdown-content'>"))
elif dropdown:
if line.startswith(" "):
print("todo")
dphtml = dphtml(HTML("<a href='" + link.strip() + "'>" + title + "</a>"))
#TODO if this is the last line, detect it by getting the future of lines[id + 1]
continue
else:
dphtml = dphtml(HTML("</div></div>"))
navbar = navbar.li(dphtml)
dropdown = False
#mark currently open tab as active when it is open
if link.strip() == pagetitle + ".page":
navbar = navbar(HTML("<div class='" + "active" + "'>"))
link = "#"
elif link.strip() == homepage + ".page":
link = "/"
else:
link = link.replace(" ", "-").replace(".page", "").lower()
#div class for styling
navbar = navbar(HTML("<div class='" + title.replace(" ", "-").lower() + "'>"))
#link and end of div
#currently open tab in navbar
if link == "#":
navbar = navbar.li(HTML("<a href='" + link.strip() + "'>" + title + "</a></div></div>"))
navbar = navbar.li(HTML("<div class='active'>" + "<a href='" + link.strip() + "'>" + title + "</a></div>"))
else:
navbar = navbar.li(HTML("<a href='" + link.strip() + "'>" + title + "</a></div>"))
navbar = navbar.li(HTML("<a href='" + link.strip() + "'>" + title + "</a>"))
print(navbar)
else:
print("Error: invalid navbar entry, line " + str(id + 1) + " content: " + line)
exit()

View File

@ -1,2 +1,7 @@
About;About.page
Home;Home.page
More;#|
Site 1;https://duckduckgo.com
Site 2;https://duckduckgo.com
Site 3;https://duckduckgo.com
Test;/test