summaryrefslogtreecommitdiff
path: root/src/website.py
blob: 2da85c507287da0424906c97ae86fe675e331027 (plain)
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
import datetime

import quart as q

SPECIAL_PATHS = ("/", "/admin/")

blueprint = q.Blueprint("website", __name__)


def label_active(path: str):
    return (
        q.request.path.startswith(path)
        if path not in SPECIAL_PATHS
        else q.request.path == path
    )


def format_timestamp(dt: datetime.datetime):
    return dt.astimezone(datetime.timezone.utc).strftime("%a %d %b %Y at %H:%M")


blueprint.add_app_template_global(label_active, "label_active")
blueprint.add_app_template_global(format_timestamp, "format_ts")


@blueprint.route("/")
async def index():
    return await q.render_template(
        "index.html", title="Home", description="home's the best place, right?"
    )


@blueprint.route("/home")
async def redirect_to_index():
    return q.redirect("/")


@blueprint.route("/projects")
async def projects():
    return await q.render_template(
        "projects.html",
        title="Projects",
        description="things I have built throughout my career",
    )


@blueprint.route("/clocks")
async def clocks():
    return await q.render_template(
        "clocks.html",
        title="Clocks",
        description="various clocks from events in my life",
    )