Better navbar styling support

This commit is contained in:
Govindas 2022-02-03 15:34:15 +02:00
parent b46b283bf2
commit b5dcc44ecb
7 changed files with 67 additions and 24 deletions

2
.gitignore vendored
View File

@ -4,4 +4,4 @@ website-output
__pycache__ __pycache__
coverage.xml coverage.xml
/gsitegen/*.page /gsitegen/*.page
resources /gsitegen/resources

View File

View File

@ -0,0 +1,35 @@
ul {
list-style-type: none;
margin: 2px;
padding: 0;
overflow: hidden;
background-color: #333;
border-radius: 25px;
float: center;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 15px 35px;
text-decoration: none;
font-size: 3.0vmin;
}
@media only screen and (max-width: 1000px) {
li a {
display: block;
color: white;
text-align: center;
padding: 15px 35px;
text-decoration: none;
font-size: 3.0vmax;
}
}
.active li a {
background-color: #04AA6D;
}

View File

@ -1,5 +1,3 @@
> >
<link href="/style.css" rel="stylesheet"> <link href="/style.css" rel="stylesheet">
<style>.about > li > a { color: lightgreen; } </style>
About page About page
ee

View File

@ -1,8 +1,7 @@
> >
<link href="/style.css" rel="stylesheet"> <link href="/style.css" rel="stylesheet">
<style>.home > li > a { color: lightgreen; } </style>
# Welcome! # Welcome!
This is the homepage of our website..... This is the homepage of our website.
> >
<b>HTML Hello</b> <b>HTML Hello</b>
Another markdown line Another markdown line

View File

@ -5,7 +5,7 @@ import html
from pathlib import Path 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. #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 generateNavigationBar(lines): def generateNavigationBar(lines, pagetitle):
global navbar global navbar
navbar = E navbar = E
rawhtml = False rawhtml = False
@ -15,17 +15,27 @@ def generateNavigationBar(lines):
#parse raw HTML #parse raw HTML
rawhtml, navbar, htmlstring = parseRawHTML(navbar, line, htmlstring, rawhtml, id, len(lines)) rawhtml, navbar, htmlstring = parseRawHTML(navbar, line, htmlstring, rawhtml, id, len(lines))
#parse markdown #parse navigation bar (custom format)
if not rawhtml: if not rawhtml:
if ";" in line: if ";" in line:
title, link = line.split(";", 1) title, link = line.split(";", 1)
#div class for styling #mark currently open tab as active when it is open
navbar = navbar(HTML("<div class='" + title.replace(" ", "-").lower() + "'>")) if link.strip() == pagetitle + ".page":
navbar = navbar(HTML("<div class='" + "active" + "'>"))
link = ""
elif link.strip() == homepage + ".page":
print(pagetitle)
link = "/"
else:
link = link.replace(" ", "-").replace(".page", "").lower()
#div class for styling
navbar = navbar(HTML("<div class='" + pagetitle.replace(" ", "-").lower() + "'>"))
#link and end of div #link and end of div
navbar = navbar.li(HTML("<a href='" + link.strip() + "'>" + title + "</a></div>")) navbar = navbar.li(HTML("<a href='" + link.strip() + "'>" + title + "</a></div></div>"))
return navbar
def generateFooter(lines): def generateFooter(lines):
global footer global footer
footer = E footer = E
@ -95,19 +105,27 @@ def generatePage(title, doc):
if 'titles' not in globals(): if 'titles' not in globals():
titles = [] titles = []
if 'navbar' in globals(): navbarfile = Path(__file__).parent.joinpath('navbar')
if navbarfile.exists():
with navbarfile.open('r') as navbarfile:
navbar = generateNavigationBar(navbarfile.readlines(), title)
if 'footer' in globals(): if 'footer' in globals():
pages.append(str(E.ul(navbar)) + str(doc) + str(E.ul(footer))) pages.append(str(E.ul(navbar)) + str(doc) + str(E.ul(footer)))
else: else:
pages.append(str(E.ul(navbar)) + str(doc)) pages.append(str(E.ul(navbar)) + str(doc))
else: else:
print("No 'navbar' file found, there will be no navigation bar.")
if 'footer' in globals(): if 'footer' in globals():
pages.append(str(doc) + str(E.ul(footer))) pages.append(str(doc) + str(E.ul(footer)))
else: else:
pages.append(str(doc)) pages.append(str(doc))
titles.append(title) titles.append(title)
def writePages(homepage): def writePages():
global pages global pages
global titles global titles
#TODO only delete files that aren't present in newest site generation #TODO only delete files that aren't present in newest site generation
@ -170,16 +188,9 @@ def writePages(homepage):
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 homepage
homepage = "Home" homepage = "Home"
navbarfile = Path(__file__).parent.joinpath('navbar')
if navbarfile.exists():
with navbarfile.open('r') as navbarfile:
generateNavigationBar(navbarfile.readlines())
else:
print("No 'navbar' file found, there will be no navigation bar.")
footerfile = Path(__file__).parent.joinpath('footer') footerfile = Path(__file__).parent.joinpath('footer')
if footerfile.exists(): if footerfile.exists():
@ -199,7 +210,7 @@ def main():
print("Found " + str(pagescount) + " pages") print("Found " + str(pagescount) + " pages")
#write all pages to files #write all pages to files
writePages(homepage) writePages()
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -1,2 +1,2 @@
About;/about About;About.page
Home;/ Home;Home.page