diff options
author | 2022-01-30 14:02:19 +0100 | |
---|---|---|
committer | 2022-01-30 14:02:19 +0100 | |
commit | 4b17d714fb0cb7d1fd199a2ca123b6d18fe377e7 (patch) | |
tree | 5d40f59ec8972eb83c32d6dfa286989e6a81a53c | |
parent | Show a duck pond when no filters match. (diff) |
Fix resource redirects for deploy previews.
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.
I don't think realistically that we're gonna be adding a ton of resource
types down the line anyway.
-rw-r--r-- | pydis_site/apps/content/urls.py | 2 | ||||
-rw-r--r-- | pydis_site/apps/resources/urls.py | 40 |
2 files changed, 40 insertions, 2 deletions
diff --git a/pydis_site/apps/content/urls.py b/pydis_site/apps/content/urls.py index fe7c2852..f8496095 100644 --- a/pydis_site/apps/content/urls.py +++ b/pydis_site/apps/content/urls.py @@ -30,7 +30,7 @@ def __get_all_files(root: Path, folder: typing.Optional[Path] = None) -> list[st def get_all_pages() -> typing.Iterator[dict[str, str]]: - """Yield a dict of all pag categories.""" + """Yield a dict of all page categories.""" for location in __get_all_files(Path("pydis_site", "apps", "content", "resources")): yield {"location": location} diff --git a/pydis_site/apps/resources/urls.py b/pydis_site/apps/resources/urls.py index ed24dc99..aa3892b6 100644 --- a/pydis_site/apps/resources/urls.py +++ b/pydis_site/apps/resources/urls.py @@ -1,9 +1,47 @@ +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]]: + 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_path( + "<resource_type>/", + views.resources.ResourceView.as_view(), + name="index", + distill_func=get_all_pages, + ), ] |