Redirects for Datasette

I made some changes to my site that resulted in cleaner URL designs, so I needed to setup some redirects. I configured the redirects using a one-off Datasette plugin called which I dropped into the plugins/ directory for the Datasette instance:

from datasette import hookimpl
from datasette.utils.asgi import Response

def register_routes():
    return (
        (r"^/til/til/(?P<topic>[^_]+)_(?P<slug>[^\.]+)\.md$", lambda request: Response.redirect(
            "/{topic}/{slug}".format(**request.url_vars), status=301
        ("^/til/feed.atom$", lambda: Response.redirect("/tils/feed.atom", status=301)),
            lambda request: Response.redirect(
                + (("?" + request.query_string) if request.query_string else ""),

Created 2020-11-25T11:53:32-08:00 · Edit