diff options
| author | alex <alex@pdp7.net> | 2023-10-13 16:11:25 +0200 |
|---|---|---|
| committer | alex <alex@pdp7.net> | 2023-10-13 16:11:25 +0200 |
| commit | 250201b433c0a99f6cabcb2596bfe43f1a5a3968 (patch) | |
| tree | 8dc5de16ed4315b3ab4fcc001b7dbd74d475c4b3 /blog_experiment/blog/__init__.py | |
| parent | 1a80ac63854ba4ea28f81194ad15314771e979d5 (diff) | |
Moving to prod!
Diffstat (limited to 'blog_experiment/blog/__init__.py')
| -rw-r--r-- | blog_experiment/blog/__init__.py | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/blog_experiment/blog/__init__.py b/blog_experiment/blog/__init__.py deleted file mode 100644 index 81332ddd..00000000 --- a/blog_experiment/blog/__init__.py +++ /dev/null @@ -1,54 +0,0 @@ -import pathlib -import re - -import bicephalus - -import htmlgenerator as h - -from blog import blog_pages, page, html, pretty, gemtext - - -class SimplePage(page.BasePage): - def __init__(self, request, url, title): - super().__init__(request) - self.url = url - self.title = title - - def get_gemini_content(self): - return ( - bicephalus.Status.OK, - "text/gemini", - pathlib.Path(f"static{self.url}index.gmi").read_text(), - ) - - def get_http_content(self): - return ( - bicephalus.Status.OK, - "text/html", - pretty.pretty_html(h.render( - h.HTML( - h.HEAD( - h.TITLE(self.title), - ), - h.BODY(*html.gemini_to_html(gemtext.parse(self.get_gemini_content()[2]))) - ), {})), - ) - - -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() - if request.path == "/about/": - return SimplePage(request, request.path, "About Álex Córcoles").response() - if request.path == "/laspelis/": - return SimplePage(request, request.path, "laspelis").response() - if re.match(r"/laspelis/\d+/?", request.path): - return SimplePage(request, request.path.removesuffix("/") + "/", request.path).response() - - return page.NotFound(request).response() |
