Better navbar styling support
This commit is contained in:
parent
b46b283bf2
commit
b5dcc44ecb
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,4 +4,4 @@ website-output
|
||||
__pycache__
|
||||
coverage.xml
|
||||
/gsitegen/*.page
|
||||
resources
|
||||
/gsitegen/resources
|
||||
|
0
example/resources/About/test.txt
Normal file
0
example/resources/About/test.txt
Normal file
35
example/resources/style.css
Normal file
35
example/resources/style.css
Normal 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;
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
>
|
||||
<link href="/style.css" rel="stylesheet">
|
||||
<style>.about > li > a { color: lightgreen; } </style>
|
||||
About page
|
||||
ee
|
||||
|
@ -1,8 +1,7 @@
|
||||
>
|
||||
<link href="/style.css" rel="stylesheet">
|
||||
<style>.home > li > a { color: lightgreen; } </style>
|
||||
# Welcome!
|
||||
This is the homepage of our website.....
|
||||
This is the homepage of our website.
|
||||
>
|
||||
<b>HTML Hello</b>
|
||||
Another markdown line
|
||||
|
@ -5,7 +5,7 @@ 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 generateNavigationBar(lines):
|
||||
def generateNavigationBar(lines, pagetitle):
|
||||
global navbar
|
||||
navbar = E
|
||||
rawhtml = False
|
||||
@ -15,17 +15,27 @@ def generateNavigationBar(lines):
|
||||
#parse raw HTML
|
||||
rawhtml, navbar, htmlstring = parseRawHTML(navbar, line, htmlstring, rawhtml, id, len(lines))
|
||||
|
||||
#parse markdown
|
||||
#parse navigation bar (custom format)
|
||||
if not rawhtml:
|
||||
if ";" in line:
|
||||
title, link = line.split(";", 1)
|
||||
|
||||
#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":
|
||||
print(pagetitle)
|
||||
link = "/"
|
||||
else:
|
||||
link = link.replace(" ", "-").replace(".page", "").lower()
|
||||
|
||||
#div class for styling
|
||||
navbar = navbar(HTML("<div class='" + title.replace(" ", "-").lower() + "'>"))
|
||||
navbar = navbar(HTML("<div class='" + pagetitle.replace(" ", "-").lower() + "'>"))
|
||||
|
||||
#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):
|
||||
global footer
|
||||
footer = E
|
||||
@ -95,19 +105,27 @@ def generatePage(title, doc):
|
||||
if 'titles' not in globals():
|
||||
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():
|
||||
pages.append(str(E.ul(navbar)) + str(doc) + str(E.ul(footer)))
|
||||
else:
|
||||
pages.append(str(E.ul(navbar)) + str(doc))
|
||||
else:
|
||||
print("No 'navbar' file found, there will be no navigation bar.")
|
||||
|
||||
if 'footer' in globals():
|
||||
pages.append(str(doc) + str(E.ul(footer)))
|
||||
else:
|
||||
pages.append(str(doc))
|
||||
|
||||
titles.append(title)
|
||||
|
||||
def writePages(homepage):
|
||||
def writePages():
|
||||
global pages
|
||||
global titles
|
||||
#TODO only delete files that aren't present in newest site generation
|
||||
@ -170,16 +188,9 @@ def writePages(homepage):
|
||||
def main():
|
||||
|
||||
#if homepage is at Home.page, set homepage to "Home"
|
||||
global homepage
|
||||
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')
|
||||
|
||||
if footerfile.exists():
|
||||
@ -199,7 +210,7 @@ def main():
|
||||
print("Found " + str(pagescount) + " pages")
|
||||
|
||||
#write all pages to files
|
||||
writePages(homepage)
|
||||
writePages()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -1,2 +1,2 @@
|
||||
About;/about
|
||||
Home;/
|
||||
About;About.page
|
||||
Home;Home.page
|
||||
|
Loading…
Reference in New Issue
Block a user