Finish dropdown in navbar
This commit is contained in:
@@ -4,7 +4,19 @@ import markdown
|
||||
import html
|
||||
from pathlib import Path
|
||||
|
||||
#TODO re-think navigation bar. Think of way to add option to display navigation bar entry differently if you're currently on that page.
|
||||
def parseLink(link, pagetitle, homepage):
|
||||
if link.strip() == pagetitle + ".page":
|
||||
return "#"
|
||||
elif link.strip() == homepage + ".page":
|
||||
return "/"
|
||||
else:
|
||||
destination = link.replace(" ", "-").replace(".page", "").lower()
|
||||
|
||||
#Start local links with / symbol
|
||||
if link.strip().endswith(".page"):
|
||||
return "/" + destination
|
||||
return destination
|
||||
|
||||
def generateNavigationBar(lines, pagetitle):
|
||||
global navbar
|
||||
navbar = E
|
||||
@@ -19,49 +31,49 @@ def generateNavigationBar(lines, pagetitle):
|
||||
#parse navigation bar (custom format)
|
||||
if not rawhtml:
|
||||
if ";" in line:
|
||||
|
||||
#experimental dropdown parsing, to be removed or used soon
|
||||
#contents = []
|
||||
#if "|" in line:
|
||||
# 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]
|
||||
link = link.strip()[:len(link.strip())-1]
|
||||
dphtml = E
|
||||
dphtml = dphtml(HTML("<div class='dropdown'><button class 'dropbutton'>Test more</button><div class='dropdown-content'>"))
|
||||
|
||||
#some duplicate logic as normal navbar entries get, to make dropdown button in itself act like a normal clickable navbar entry
|
||||
link = parseLink(link, pagetitle, homepage)
|
||||
if link.strip() == "#":
|
||||
dphtml = dphtml(HTML("<div class='dropdown'><div class='dropbutton'><div class='active'><a href='" + link.strip() + "'>" + title + "</a></div></div><div class='dropdown-content'>"))
|
||||
else:
|
||||
dphtml = dphtml(HTML("<div class='dropdown'><div class='dropbutton'><a href='" + link.strip() + "'>" + title + "</a></div><div class='dropdown-content'>"))
|
||||
continue
|
||||
|
||||
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":
|
||||
link = "#"
|
||||
elif link.strip() == homepage + ".page":
|
||||
link = "/"
|
||||
else:
|
||||
link = link.replace(" ", "-").replace(".page", "").lower()
|
||||
|
||||
#currently open tab in navbar
|
||||
if link == "#":
|
||||
link = parseLink(link, pagetitle, homepage)
|
||||
if link.strip() == "#":
|
||||
dphtml = dphtml(HTML("<div class='active'><a href='" + link.strip() + "'>" + title + "</a></div>"))
|
||||
else:
|
||||
dphtml = dphtml(HTML("<a href='" + link.strip() + "'>" + title + "</a>"))
|
||||
|
||||
#handle end of indentation (if indented line is the last line of page or next line is not indented)
|
||||
if len(lines) - id == 1 or lines[id + 1].startswith(" ") is False:
|
||||
dphtml = dphtml(HTML("</div></div>"))
|
||||
navbar = navbar.li(dphtml)
|
||||
dropdown = False
|
||||
continue
|
||||
|
||||
#mark currently open tab as active when it is open
|
||||
link = parseLink(link, pagetitle, homepage)
|
||||
if link.strip() == "#":
|
||||
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>"))
|
||||
print(navbar)
|
||||
continue
|
||||
|
||||
navbar = navbar.li(HTML("<a href='" + link.strip() + "'>" + title + "</a>"))
|
||||
else:
|
||||
print("Error: invalid navbar entry, line " + str(id + 1) + " content: " + line)
|
||||
exit()
|
||||
return navbar
|
||||
|
||||
def generateFooter(lines):
|
||||
global footer
|
||||
footer = E
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
About;About.page
|
||||
Home;Home.page
|
||||
More;#|
|
||||
Site 1;https://duckduckgo.com
|
||||
More;More.page|
|
||||
About;About.page
|
||||
Site 2;https://duckduckgo.com
|
||||
Site 3;https://duckduckgo.com
|
||||
Test;/test
|
||||
|
||||
Reference in New Issue
Block a user