2025-01-30 21:15:57 -08:00
|
|
|
# Copyright (C) 2025 Daniel McKnight - All Rights Reserved
|
2025-01-30 20:05:16 -08:00
|
|
|
|
2025-01-30 21:15:57 -08:00
|
|
|
from os.path import isfile, join, dirname
|
2025-01-30 20:05:16 -08:00
|
|
|
from nicegui import ui
|
|
|
|
|
|
|
|
_tab_to_content = {
|
|
|
|
"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"
|
|
|
|
|
|
|
|
def _get_content_from_file(file_name: str) -> str:
|
|
|
|
"""
|
|
|
|
Take a file name/path and return its contents
|
|
|
|
:param file_name: Relative or absolute path to a file
|
|
|
|
"""
|
2025-01-30 21:15:57 -08:00
|
|
|
file_name = join(dirname(__file__), file_name)
|
|
|
|
if not isfile(file_name):
|
2025-01-30 20:05:16 -08:00
|
|
|
file_name = _error_page
|
2025-01-30 21:15:57 -08:00
|
|
|
with open(file_name, 'r') as f:
|
2025-01-30 20:05:16 -08:00
|
|
|
return f.read()
|
|
|
|
|
|
|
|
def render_tab(tab_name: str):
|
|
|
|
file_name = _tab_to_content.get(tab_name, _error_page)
|
2025-01-30 21:34:55 -08:00
|
|
|
ui.markdown(_get_content_from_file(file_name), extras=['cuddled-lists', 'fenced-code-blocks', 'tables'])
|
2025-01-30 20:05:16 -08:00
|
|
|
|
|
|
|
|
|
|
|
def render_header() -> ui.tab_panels:
|
|
|
|
"""
|
|
|
|
Render sticky page header with navigation
|
|
|
|
"""
|
|
|
|
tab_names = _tab_to_content.keys()
|
|
|
|
with ui.tabs().classes('w-full') as tabs:
|
2025-01-30 21:15:57 -08:00
|
|
|
tab_list = {name: ui.tab(name) for name in tab_names}
|
2025-01-30 20:05:16 -08:00
|
|
|
with ui.tab_panels(tabs).classes('w-full') as header:
|
2025-01-30 21:15:57 -08:00
|
|
|
for name, t in tab_list.items():
|
2025-01-30 20:05:16 -08:00
|
|
|
with ui.tab_panel(t):
|
2025-01-30 21:15:57 -08:00
|
|
|
render_tab(name)
|
2025-01-30 20:05:16 -08:00
|
|
|
return header
|
|
|
|
|
|
|
|
def main():
|
|
|
|
header = render_header()
|
|
|
|
header.set_value(list(_tab_to_content.keys())[0])
|
|
|
|
ui.run(dark=None)
|
|
|
|
|
|
|
|
|
2025-01-30 21:15:57 -08:00
|
|
|
main()
|