from fh_bootstrap import * from itertools import chain from markdown import markdown md_exts = "codehilite", "smarty", "extra", "sane_lists" def Markdown(s, exts=md_exts, **kw): return Div(NotStr(markdown(s, extensions=exts)), **kw) ghurl = "https://github.com/nbroad1881" hf_logo_svg = ( "https://huggingface.co/datasets/huggingface/brand-assets/resolve/main/hf-logo.svg" ) hf_url = "https://hf.co/nbroad" li_url = "https://www.linkedin.com/in/nicholas-m-broad/" kaggle_url = "https://www.kaggle.com/nbroad" yt_url = "https://www.youtube.com/@nicholasbroad1881" tw_url = "https://twitter.com/nbroad1881" fh_url = "https://fastht.ml/" fh_logo = "assets/fasthtml_logo.svg" def BstPage(selidx, title, *c): navitems = [("Home", "/"), ("About", "/about"), ("Blog", "/blog")] ra_items = ( A( Image( src=hf_logo_svg, width=28, height=28, cls="my-0 px-0 mx-0 py-0", left=False, pad=0, ), cls="ms-2 my-0 px-1 btn-lg btn", role="button", href=hf_url, target="_blank", rel="noopener noreferrer", ), Icon( "fab fa-github", dark=False, sz="lg", href=ghurl, cls="ms-2 px-2", target="_blank", rel="noopener noreferrer", ), Icon( "fab fa-linkedin", dark=False, sz="lg", href=li_url, cls="ms-2 px-2", target="_blank", rel="noopener noreferrer", ), Icon( "fab fa-kaggle", dark=False, sz="lg", href=kaggle_url, cls="ms-2 px-2", target="_blank", rel="noopener noreferrer", ), Icon( "fab fa-youtube", dark=False, sz="lg", href=yt_url, cls="ms-2 px-2", target="_blank", rel="noopener noreferrer", ), Icon( "fab fa-twitter", dark=False, sz="lg", href=tw_url, cls="ms-2 px-2", target="_blank", rel="noopener noreferrer", ), ) ftlinks = [ A(k, href=v, cls="nav-link px-2 text-muted") for k, v in dict(Home="/").items() ] return ( Title(title), Script("initTOC()"), Container( Navbar( "nav", selidx, items=navitems, ra_items=ra_items, cls="navbar-light bg-secondary rounded-lg", image=f"", hdr_href="", placement=PlacementT.Default, expand=SizeT.Md, toggle_left=False, ), Toc(Container(H1(title, cls="pb-2 pt-1"), *c, cls="mt-3")), BstFooter( "Made using FastHTML", File(fh_logo), img_href=fh_url, cs=ftlinks ), typ=ContainerT.Xl, cls="mt-3", data_bs_spy="scroll", data_bs_target="#toc", ), ) def Sections(h2s, texts): colors = "yellow", "pink", "teal", "blue" div_cls = "py-2 px-3 mt-4 bg-light-{} rounded-lg" return chain( [ Div( H2(h2, id=f"sec{i+1}", cls=div_cls.format(colors[i % 4])), Div(txt, cls="px-2"), ) for i, (h2, txt) in enumerate(zip(h2s, texts)) ] )