2022-09-04 17:23:41 +01:00
|
|
|
import re
|
|
|
|
|
2022-06-09 08:36:29 +01:00
|
|
|
from django.conf import settings
|
2022-06-15 09:27:20 +01:00
|
|
|
from django.urls import include, path, re_path
|
2022-09-04 17:23:41 +01:00
|
|
|
from django.views.decorators.cache import cache_control, cache_page
|
2022-09-05 14:17:48 +01:00
|
|
|
from django.views.defaults import server_error
|
2023-03-06 14:32:00 +00:00
|
|
|
from django.views.generic import RedirectView
|
2022-09-04 17:23:41 +01:00
|
|
|
from django.views.static import serve
|
2022-06-09 08:36:29 +01:00
|
|
|
from wagtail import urls as wagtail_urls
|
2022-06-12 15:17:28 +01:00
|
|
|
from wagtail.admin import urls as wagtailadmin_urls
|
2022-08-02 22:20:36 +01:00
|
|
|
from wagtail.contrib.sitemaps.views import sitemap
|
2022-06-09 08:36:29 +01:00
|
|
|
from wagtail.documents import urls as wagtaildocs_urls
|
2022-06-15 09:27:20 +01:00
|
|
|
from wagtail.images.views.serve import ServeView
|
2022-08-27 23:44:56 +01:00
|
|
|
from wagtail_favicon.urls import urls as favicon_urls
|
2022-08-28 16:18:31 +01:00
|
|
|
from wagtailautocomplete.urls.admin import urlpatterns as autocomplete_admin_urls
|
2022-06-09 08:36:29 +01:00
|
|
|
|
2022-08-25 14:11:47 +01:00
|
|
|
from website.common.views import AllPagesFeed, KeybaseView, RobotsView, page_not_found
|
2022-08-19 09:36:03 +01:00
|
|
|
|
2022-06-09 08:36:29 +01:00
|
|
|
urlpatterns = [
|
2022-08-28 16:18:31 +01:00
|
|
|
path("admin/autocomplete/", include(autocomplete_admin_urls)),
|
2022-06-09 08:36:29 +01:00
|
|
|
path("admin/", include(wagtailadmin_urls)),
|
|
|
|
path("documents/", include(wagtaildocs_urls)),
|
2022-06-27 23:29:55 +01:00
|
|
|
path(
|
2022-07-16 01:13:48 +01:00
|
|
|
"code-block/",
|
|
|
|
include("website.contrib.code_block.urls"),
|
2022-06-27 23:29:55 +01:00
|
|
|
),
|
2022-08-22 20:33:52 +01:00
|
|
|
path(".well-known/", include("website.well_known.urls")),
|
2022-06-15 09:27:20 +01:00
|
|
|
re_path(
|
|
|
|
r"^images/([^/]*)/(\d*)/([^/]*)/[^/]*$",
|
|
|
|
ServeView.as_view(action="redirect"),
|
|
|
|
name="wagtailimages_serve",
|
|
|
|
),
|
2022-08-20 18:31:08 +01:00
|
|
|
path("sitemap.xml", cache_page(60 * 60)(sitemap), name="sitemap"),
|
2022-09-04 17:29:04 +01:00
|
|
|
path(
|
|
|
|
"robots.txt",
|
2022-10-02 18:53:51 +01:00
|
|
|
RobotsView.as_view(),
|
2022-09-04 17:29:04 +01:00
|
|
|
name="robotstxt",
|
|
|
|
),
|
|
|
|
path(
|
|
|
|
"keybase.txt",
|
2022-10-02 18:53:51 +01:00
|
|
|
KeybaseView.as_view(),
|
2022-09-04 17:29:04 +01:00
|
|
|
name="keybase",
|
|
|
|
),
|
2022-08-22 21:32:38 +01:00
|
|
|
path("feed/", AllPagesFeed(), name="feed"),
|
2022-09-05 13:35:48 +01:00
|
|
|
path(".health/", include("health_check.urls")),
|
2022-08-22 21:11:46 +01:00
|
|
|
path("", include("website.legacy.urls")),
|
2022-10-02 19:20:40 +01:00
|
|
|
path("api/", include("website.api.urls", namespace="api")),
|
2023-03-06 14:32:00 +00:00
|
|
|
path(
|
|
|
|
"@jake",
|
|
|
|
RedirectView.as_view(url=f"https://{settings.ACTIVITYPUB_HOST}/@jake"),
|
|
|
|
),
|
2022-08-27 23:44:56 +01:00
|
|
|
path("", include(favicon_urls)),
|
2022-06-09 08:36:29 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-08-19 09:36:03 +01:00
|
|
|
if not settings.DEBUG:
|
|
|
|
handler404 = "website.common.views.page_not_found"
|
|
|
|
|
|
|
|
|
2022-06-09 08:36:29 +01:00
|
|
|
if settings.DEBUG:
|
2022-06-13 22:43:54 +01:00
|
|
|
# Add django-browser-reload
|
|
|
|
urlpatterns.append(path("__reload__/", include("django_browser_reload.urls")))
|
|
|
|
|
2022-06-14 22:23:44 +01:00
|
|
|
# Add django-debug-toolbar
|
|
|
|
urlpatterns.append(path("__debug__/", include("debug_toolbar.urls")))
|
|
|
|
|
2023-02-21 21:41:31 +00:00
|
|
|
urlpatterns.append(
|
|
|
|
# Media is served by nginx in production
|
|
|
|
re_path(
|
|
|
|
r"^%s(?P<path>.*)$" % re.escape(settings.MEDIA_URL.lstrip("/")),
|
|
|
|
cache_control(max_age=60 * 60)(serve),
|
|
|
|
{"document_root": settings.MEDIA_ROOT},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2022-10-02 19:25:36 +01:00
|
|
|
|
|
|
|
if settings.DEBUG or settings.TEST:
|
|
|
|
urlpatterns.extend(
|
|
|
|
[
|
|
|
|
path("404/", page_not_found, name="404"),
|
|
|
|
path("500/", server_error, name="500"),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2022-06-09 08:36:29 +01:00
|
|
|
urlpatterns = urlpatterns + [
|
|
|
|
# For anything not caught by a more specific rule above, hand over to
|
|
|
|
# Wagtail's page serving mechanism. This should be the last pattern in
|
|
|
|
# the list:
|
|
|
|
path("", include(wagtail_urls)),
|
|
|
|
# Alternatively, if you want Wagtail pages to be served from a subpath
|
|
|
|
# of your site, rather than the site root:
|
|
|
|
# path("pages/", include(wagtail_urls)),
|
|
|
|
]
|