File size: 3,607 Bytes
3fb26c5
 
 
 
9d1d9ac
3fb26c5
9d1d9ac
 
 
 
 
 
 
 
 
addf7c0
3fb26c5
 
addf7c0
 
3fb26c5
9d1d9ac
 
3fb26c5
 
9d1d9ac
 
3fb26c5
addf7c0
9d1d9ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addf7c0
9d1d9ac
 
 
3fb26c5
 
9d1d9ac
3fb26c5
9d1d9ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3fb26c5
 
9d1d9ac
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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))
        ]
    )