Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
templates: Add rel-canonical link to some documentation pages.
Lauryn Menard6fb19fdd2dd8
diff --git a/templates/zerver/meta_tags.html b/templates/zerver/meta_tags.htmlindex 8e92dca24e7..aa1168b49ce 100644--- a/templates/zerver/meta_tags.html+++ b/templates/zerver/meta_tags.html@@ -1,4 +1,7 @@<!-- Google / search engine tags -->+{% if REL_CANONICAL_LINK %}+<link rel="canonical" href="{{ REL_CANONICAL_LINK }}" />+{% endif %}{% if allow_search_engine_indexing %}{% if PAGE_DESCRIPTION %}<meta name="description" content="{{ PAGE_DESCRIPTION }}" />diff --git a/zerver/views/documentation.py b/zerver/views/documentation.pyindex aff82efc032..626ef32d327 100644--- a/zerver/views/documentation.py+++ b/zerver/views/documentation.py@@ -76,6 +76,10 @@ def add_api_url_context(context["html_settings_links"] = html_settings_links+def add_canonical_link_context(context: dict[str, Any], request: HttpRequest) -> None:+ context["REL_CANONICAL_LINK"] = f"https://zulip.com{request.path}"++class ApiURLView(TemplateView):@overridedef get_context_data(self, **kwargs: Any) -> dict[str, str]:@@ -200,6 +204,9 @@ class MarkdownDirectoryView(ApiURLView):else:sidebar_index = Nonetitle_base = "Zulip terms and policies"+ # We don't add a rel-canonical link to self-hosted server policies docs.+ if settings.CORPORATE_ENABLED:+ add_canonical_link_context(context, self.request)elif self.api_doc_view:context["page_is_api_center"] = Truecontext["doc_root"] = "/api/"@@ -207,6 +214,7 @@ class MarkdownDirectoryView(ApiURLView):sidebar_article = self.get_path("sidebar_index")sidebar_index = sidebar_article.article_pathtitle_base = "Zulip API documentation"+ add_canonical_link_context(context, self.request)else:raise AssertionError("Invalid documentation view type")@@ -364,6 +372,7 @@ class IntegrationView(ApiURLView):context: dict[str, Any] = super().get_context_data(**kwargs)add_integrations_context(context)add_integrations_open_graph_context(context, self.request)+ add_canonical_link_context(context, self.request)add_google_analytics_context(context)return context