docs: Remove trailing slash from canonical URL for non-root docs.

The root pages for API, integrations and policies documentation
have a trailing slash for the canoncial URL, but the individual
articles on those pages do not have a trailing slash for the page
we want to mark as canonical.
This commit is contained in:
Lauryn Menard
2025-10-22 16:26:11 +02:00
committed by Alex Vandiver
parent e9cdf6f41c
commit 9de4618202
2 changed files with 14 additions and 1 deletions

View File

@@ -251,6 +251,14 @@ class DocPageTest(ZulipTestCase):
) )
self.assertEqual(result.status_code, 404) self.assertEqual(result.status_code, 404)
result = self.client_get(
# Non-root API docs pages do not have a trailing slash.
"/api/changelog/",
follow=True,
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
)
self.assertEqual(result.status_code, 404)
def test_dev_environment_endpoints(self) -> None: def test_dev_environment_endpoints(self) -> None:
self._test("/devlogin/", ["Normal users"]) self._test("/devlogin/", ["Normal users"])
self._test("/devtools/", ["Useful development URLs"]) self._test("/devtools/", ["Useful development URLs"])

View File

@@ -77,7 +77,12 @@ def add_api_url_context(
def add_canonical_link_context(context: dict[str, Any], request: HttpRequest) -> None: def add_canonical_link_context(context: dict[str, Any], request: HttpRequest) -> None:
context["REL_CANONICAL_LINK"] = f"https://zulip.com{request.path}" if request.path in ["/api/", "/policies/", "/integrations/"]:
# Root doc pages have a trailing slash in the canonical URL.
canonical_path = request.path
else:
canonical_path = request.path.removesuffix("/")
context["REL_CANONICAL_LINK"] = f"https://zulip.com{canonical_path}"
class ApiURLView(TemplateView): class ApiURLView(TemplateView):