aboutsummaryrefslogtreecommitdiff
path: root/blog_experiment/blog/__init__.py
blob: 594d1a77dadd66fc91067f5fcf72951a7110b394 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import pathlib
import re

import bicephalus

from blog import blog_pages, page


def handler(request: bicephalus.Request) -> bicephalus.Response:
    if request.path == "/":
        return blog_pages.Root(request).response()
    if re.match(r"/\d{4}/\d{2}/.*/", request.path):
        blog_file = pathlib.Path("content") / (request.path[1:-1] + ".gmi")
        if blog_file.exists():
            return blog_pages.EntryPage(request, blog_file).response()
    if request.path == "/feed/" and request.proto == bicephalus.Proto.HTTP:
        return blog_pages.Root(request).feed()
    return page.NotFound(request).response()