Repository: python-discord/site

Issue:
Consider dropping deploy preview support for redirects app
Do we need previews of the legacy redirects?

If not, we may be able to remove a lot of code from the redirects app.


Discussion:
@HassanAbouelela do you know if we can action this issue somehow?
Part of the issue is we use some redirects even within the main site, particularly in things like nav. Removing the redirects from static builds makes parts of the site non-functional.
Does this still apply if we fix #681 ?
It would definitely resolve the issue in the short term, but we'd encounter the same issue in the future if we change other links.

Resolving patch:
diff --git a/pydis_site/apps/redirect/urls.py b/pydis_site/apps/redirect/urls.py
--- a/pydis_site/apps/redirect/urls.py
+++ b/pydis_site/apps/redirect/urls.py
@@ -3,14 +3,9 @@
 
 import yaml
 from django import conf
-from django.http import HttpResponse
 from django.urls import URLPattern, path
-from django_distill import distill_path
 
-from pydis_site import settings
-from pydis_site.apps.content import urls as pages_urls
 from pydis_site.apps.redirect.views import CustomRedirectView
-from pydis_site.apps.resources import urls as resources_urls
 
 app_name = "redirect"
 
@@ -31,72 +26,15 @@ class Redirect:
 
 
 def map_redirect(name: str, data: Redirect) -> list[URLPattern]:
-    """Return a pattern using the Redirects app, or a static HTML redirect for static builds."""
-    if not settings.STATIC_BUILD:
-        # Normal dynamic redirect
-        return [path(
-            data.original_path,
-            CustomRedirectView.as_view(
-                pattern_name=data.redirect_route,
-                static_args=tuple(data.redirect_arguments),
-                prefix_redirect=data.prefix_redirect
-            ),
-            name=name
-        )]
-
-    # Create static HTML redirects for static builds
-    new_app_name = data.redirect_route.split(":")[0]
-
-    if __PARAMETER_REGEX.search(data.original_path):
-        # Redirects for paths which accept parameters
-        # We generate an HTML redirect file for all possible entries
-        paths = []
-
-        class RedirectFunc:
-            def __init__(self, new_url: str, _name: str):
-                self.result = HttpResponse(REDIRECT_TEMPLATE.format(url=new_url))
-                self.__qualname__ = _name
-
-            def __call__(self, *args, **kwargs):
-                return self.result
-
-        if new_app_name == resources_urls.app_name:
-            items = resources_urls.get_all_resources()
-        elif new_app_name == pages_urls.app_name:
-            items = pages_urls.get_all_pages()
-        else:
-            raise ValueError(f"Unknown app in redirect: {new_app_name}")
-
-        for item in items:
-            entry = next(iter(item.values()))
-
-            # Replace dynamic redirect with concrete path
-            concrete_path = __PARAMETER_REGEX.sub(entry, data.original_path)
-            new_redirect = f"/{new_app_name}/{entry}"
-            pattern_name = f"{name}_{entry}"
-
-            paths.append(distill_path(
-                concrete_path,
-                RedirectFunc(new_redirect, pattern_name),
-                name=pattern_name
-            ))
-
-        return paths
-
-    redirect_path_name = "pages" if new_app_name == "content" else new_app_name
-    if len(data.redirect_arguments) > 0:
-        redirect_arg = data.redirect_arguments[0]
-    else:
-        redirect_arg = "resources/"
-    new_redirect = f"/{redirect_path_name}/{redirect_arg}"
-
-    if new_redirect == "/resources/resources/":
-        new_redirect = "/resources/"
-
-    return [distill_path(
+    """Return a pattern using the Redirects app."""
+    return [path(
         data.original_path,
-        lambda *args: HttpResponse(REDIRECT_TEMPLATE.format(url=new_redirect)),
-        name=name,
+        CustomRedirectView.as_view(
+            pattern_name=data.redirect_route,
+            static_args=tuple(data.redirect_arguments),
+            prefix_redirect=data.prefix_redirect
+        ),
+        name=name
     )]
 
 


Test patch: