Update homepage content
Add path router to allow URL navigation to specific pages
This commit is contained in:
		
							parent
							
								
									5093166559
								
							
						
					
					
						commit
						3ac9aaed04
					
				
					 2 changed files with 34 additions and 9 deletions
				
			
		|  | @ -1,20 +1,32 @@ | |||
| # Copyright (C) 2025 Daniel McKnight - All Rights Reserved | ||||
| 
 | ||||
| from os.path import isfile, join, dirname | ||||
| from typing import Optional | ||||
| 
 | ||||
| from fastapi.openapi.models import RequestBody | ||||
| from nicegui import ui | ||||
| from fastapi.requests import Request | ||||
| 
 | ||||
| # TODO: Read from configuration | ||||
| _tab_to_content = { | ||||
|     "Home": "page_content/home.md", | ||||
|     "Portfolio": "page_content/portfolio.md", | ||||
|     "Resume": "page_content/resume.md", | ||||
|     "Bio": "page_content/bio.md" | ||||
|     "home": "page_content/home.md", | ||||
|     "portfolio": "page_content/portfolio.md", | ||||
|     "resume": "page_content/resume.md", | ||||
|     "bio": "page_content/bio.md" | ||||
| } | ||||
| 
 | ||||
| _error_page = "page_content/404.md" | ||||
| _footer_block = "page_content/footer.html" | ||||
| 
 | ||||
| 
 | ||||
| @ui.page("/{name}") | ||||
| def _render_path(name: str): | ||||
|     """ | ||||
|     Parse a path element to render a page | ||||
|     :param name: path element of the request | ||||
|     """ | ||||
|     render_site(name) | ||||
| 
 | ||||
| def _get_content_from_file(file_name: str) -> str: | ||||
|     """ | ||||
|     Take a file name/path and return its contents | ||||
|  | @ -38,7 +50,7 @@ def render_tab(tab_name: str): | |||
|                     extras=['cuddled-lists', 'fenced-code-blocks', 'tables']) | ||||
| 
 | ||||
| 
 | ||||
| def render_main() -> ui.tab_panels: | ||||
| def render_header() -> ui.tab_panels: | ||||
|     """ | ||||
|     Render sticky page header with navigation | ||||
|     """ | ||||
|  | @ -51,8 +63,16 @@ def render_main() -> ui.tab_panels: | |||
|                 render_tab(name) | ||||
|     return header | ||||
| 
 | ||||
| def main(): | ||||
|     header = render_main() | ||||
| 
 | ||||
| def render_site(page_name: Optional[str] = None): | ||||
|     """ | ||||
|     Renders the site with the requested page active | ||||
|     :param page_name: Page to render. If `None` or invalid, `Home` will be rendered | ||||
|     """ | ||||
|     header = render_header() | ||||
|     if page_name and page_name in _tab_to_content.keys(): | ||||
|         header.set_value(page_name) | ||||
|     else: | ||||
|         header.set_value(list(_tab_to_content.keys())[0]) | ||||
|     ui.query('.nicegui-content').classes('h-screen no-wrap') | ||||
|     ui.html(_get_content_from_file(_footer_block), tag="footer").classes("rounded-lg shadow-sm m-4 w-full text-center") | ||||
|  | @ -64,6 +84,9 @@ def main(): | |||
|                  vertical-align: bottom; | ||||
|                } | ||||
|                 """) | ||||
| 
 | ||||
| def main(): | ||||
|     render_site() | ||||
|     ui.run(dark=None, reload=False, title="Daniel McKnight") | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +1,8 @@ | |||
| # Daniel McKnight | ||||
| ## Coder, Sysadmin, Manager | ||||
| 
 | ||||
| I work in the design and implementation of voice assistants, LLMs, infrastructure, and plenty more. | ||||
| I work in the design and implementation of voice assistants, LLMs, infrastructure, and plenty more. Check out a selection | ||||
| of my work [in my portfolio](https://www.mcknight.tech/portfolio) or learn some more about me and my experience  | ||||
| [in my bio](https://www.mcknight.tech/bio) and [resume](https://www.mcknight.tech/resume), respectively. | ||||
| I built this site using [NiceGUI](https://nicegui.io/), with the source code available  | ||||
| [on Forgejo](https://forge.mcknight.tech/d_mcknight/website-mcknight-tech). | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue