From b5dcc44ecb3f97cd4b10f893c07cc5db6cb057a1 Mon Sep 17 00:00:00 2001 From: Govindas Date: Thu, 3 Feb 2022 15:34:15 +0200 Subject: [PATCH] Better navbar styling support --- .gitignore | 2 +- example/resources/About/test.txt | 0 example/resources/style.css | 35 +++++++++++++++++++++++++ gsitegen/About.page | 2 -- gsitegen/Home.page | 3 +-- gsitegen/generate.py | 45 ++++++++++++++++++++------------ gsitegen/navbar | 4 +-- 7 files changed, 67 insertions(+), 24 deletions(-) create mode 100644 example/resources/About/test.txt create mode 100644 example/resources/style.css diff --git a/.gitignore b/.gitignore index 872dc15..8ed8b4c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ website-output __pycache__ coverage.xml /gsitegen/*.page -resources +/gsitegen/resources diff --git a/example/resources/About/test.txt b/example/resources/About/test.txt new file mode 100644 index 0000000..e69de29 diff --git a/example/resources/style.css b/example/resources/style.css new file mode 100644 index 0000000..6c88f2d --- /dev/null +++ b/example/resources/style.css @@ -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; +} diff --git a/gsitegen/About.page b/gsitegen/About.page index f83d9a3..39db5aa 100644 --- a/gsitegen/About.page +++ b/gsitegen/About.page @@ -1,5 +1,3 @@ > - About page -ee diff --git a/gsitegen/Home.page b/gsitegen/Home.page index 97a5aa7..39d5cda 100644 --- a/gsitegen/Home.page +++ b/gsitegen/Home.page @@ -1,8 +1,7 @@ > - # Welcome! -This is the homepage of our website..... +This is the homepage of our website. > HTML Hello Another markdown line diff --git a/gsitegen/generate.py b/gsitegen/generate.py index ac78d11..c559d13 100644 --- a/gsitegen/generate.py +++ b/gsitegen/generate.py @@ -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) - #div class for styling - navbar = navbar(HTML("
")) + #mark currently open tab as active when it is open + if link.strip() == pagetitle + ".page": + navbar = navbar(HTML("
")) + link = "" + elif link.strip() == homepage + ".page": + print(pagetitle) + link = "/" + else: + link = link.replace(" ", "-").replace(".page", "").lower() + + #div class for styling + navbar = navbar(HTML("
")) #link and end of div - navbar = navbar.li(HTML("" + title + "
")) - + navbar = navbar.li(HTML("" + title + "
")) + 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() diff --git a/gsitegen/navbar b/gsitegen/navbar index 5be290d..f13db9e 100644 --- a/gsitegen/navbar +++ b/gsitegen/navbar @@ -1,2 +1,2 @@ -About;/about -Home;/ +About;About.page +Home;Home.page