aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/resources/urls.py
blob: 044f70729447473e70129ab6584670e3eb25390b (plain) (blame)
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
import typing

from django_distill import distill_path

from pydis_site.apps.resources import views

# This is only used for `distill_path`, so that the Netlify Deploy Previews
# can successfully redirect to static pages. This could probably be improved by
# making it less hardcoded, but since there's a bunch of special cases, and since
# it only affects deploy previews, I'm choosing to solve this with a simple solution.
VALID_RESOURCE_TYPES = [
    "book",
    "books",
    "reading",
    "podcast",
    "podcasts",
    "interactive",
    "videos",
    "video",
    "courses",
    "course",
    "communities",
    "community",
    "tutorial",
    "tutorials",
    "tool",
    "tools",
    "project ideas",
    "project-ideas",
]


def get_all_pages() -> typing.Iterator[dict[str, str]]:
    """Get all the valid options for the resource_type path selector."""
    for resource_type in VALID_RESOURCE_TYPES:
        yield {"resource_type": resource_type}


app_name = "resources"
urlpatterns = [
    distill_path("", views.resources.ResourceView.as_view(), name="index"),
    distill_path(
        "<resource_type>/",
        views.resources.ResourceView.as_view(),
        name="index",
        distill_func=get_all_pages,
    ),
]