From 9de461820261088d06fbe81f45708516ce59b07f Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Wed, 22 Oct 2025 16:26:11 +0200 Subject: [PATCH] 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. --- zerver/tests/test_docs.py | 8 ++++++++ zerver/views/documentation.py | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py index bb9c7d25c2..c79146956e 100644 --- a/zerver/tests/test_docs.py +++ b/zerver/tests/test_docs.py @@ -251,6 +251,14 @@ class DocPageTest(ZulipTestCase): ) 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: self._test("/devlogin/", ["Normal users"]) self._test("/devtools/", ["Useful development URLs"]) diff --git a/zerver/views/documentation.py b/zerver/views/documentation.py index 626ef32d32..4f075738a8 100644 --- a/zerver/views/documentation.py +++ b/zerver/views/documentation.py @@ -77,7 +77,12 @@ def add_api_url_context( 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):