Finish dropdown in navbar
This commit is contained in:
parent
6c06865726
commit
f4de859172
3
example/More.page
Normal file
3
example/More.page
Normal file
@ -0,0 +1,3 @@
|
||||
>
|
||||
<link href="/style.css" rel="stylesheet">
|
||||
**This is More page.**
|
@ -1,2 +1,6 @@
|
||||
About;About.page
|
||||
Home;Home.page
|
||||
More;More.page|
|
||||
About;About.page
|
||||
Site 2;https://duckduckgo.com
|
||||
Site 3;https://duckduckgo.com
|
||||
|
@ -30,6 +30,58 @@ li a {
|
||||
font-size: 3.0vmax;
|
||||
}
|
||||
}
|
||||
.active li a {
|
||||
.active {
|
||||
background-color: #04AA6D;
|
||||
}
|
||||
/* Dropdown button */
|
||||
.dropdown .dropbutton {
|
||||
display: block;
|
||||
border: none;
|
||||
color: white;
|
||||
text-align: center;
|
||||
padding: 15px 35px;
|
||||
text-decoration: none;
|
||||
font-size: 3.0vmin;
|
||||
background-color: inherit;
|
||||
}
|
||||
@media only screen and (max-width: 1000px) {
|
||||
.dropdown .dropbutton {
|
||||
border: none;
|
||||
display: block;
|
||||
color: white;
|
||||
|
||||
text-align: center;
|
||||
padding: 15px 35px;
|
||||
text-decoration: none;
|
||||
font-size: 3.0vmax;
|
||||
background-color: inherit;
|
||||
}
|
||||
}
|
||||
/* Dropdown content (hidden by default) */
|
||||
.dropdown-content {
|
||||
display: none;
|
||||
position: absolute;
|
||||
background-color: #333;
|
||||
min-width: 160px;
|
||||
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
|
||||
z-index: 1;
|
||||
}
|
||||
/* Links inside the dropdown */
|
||||
.dropdown-content a {
|
||||
float: none;
|
||||
color: white;
|
||||
padding: 12px 16px;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
/* Add a grey background color to dropdown links on hover */
|
||||
.dropdown-content a:hover {
|
||||
background-color: #ddd;
|
||||
}
|
||||
|
||||
/* Show the dropdown menu on hover */
|
||||
.dropdown:hover .dropdown-content {
|
||||
display: block;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user