Refactor into module
Add Dockerfile with kluges Update portfolio
This commit is contained in:
parent
53df537650
commit
7ebdeeaa3c
9 changed files with 37 additions and 8 deletions
50
site_mcknight_tech/__main__.py
Executable file
50
site_mcknight_tech/__main__.py
Executable file
|
|
@ -0,0 +1,50 @@
|
|||
# Copyright (C) 2025 Daniel McKnight - All Rights Reserved
|
||||
|
||||
from os.path import isfile, join, dirname
|
||||
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
|
||||
"""
|
||||
file_name = join(dirname(__file__), file_name)
|
||||
if not isfile(file_name):
|
||||
file_name = _error_page
|
||||
with open(file_name, 'r') as f:
|
||||
return f.read()
|
||||
|
||||
def render_tab(tab_name: str):
|
||||
file_name = _tab_to_content.get(tab_name, _error_page)
|
||||
ui.markdown(_get_content_from_file(file_name))
|
||||
|
||||
|
||||
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:
|
||||
tab_list = {name: ui.tab(name) for name in tab_names}
|
||||
with ui.tab_panels(tabs).classes('w-full') as header:
|
||||
for name, t in tab_list.items():
|
||||
with ui.tab_panel(t):
|
||||
render_tab(name)
|
||||
return header
|
||||
|
||||
def main():
|
||||
header = render_header()
|
||||
header.set_value(list(_tab_to_content.keys())[0])
|
||||
ui.run(dark=None)
|
||||
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue