mirror of
https://github.com/zulip/zulip.git
synced 2025-10-24 08:33:43 +00:00
templates: Add rel-canonical link to documentation pages.
Updates templates/zerver/meta_tags.html to add a rel-canonical link if REL_CANONICAL_LINK is in the template context dict. We add REL_CANONICAL_LINK to the documentation context for the help center, API and integrations documentation pages in all cases. For policies documentation pages, we add REL_CANONICAL_LINK to the context only when settings.CORPORATE_ENABLED is true, so that self-hosted servers' policies documentation do not have a rel-canonical link set.
This commit is contained in:
committed by
Tim Abbott
parent
a45878a41a
commit
db0b50089b
@@ -1,4 +1,7 @@
|
|||||||
<!-- Google / search engine tags -->
|
<!-- Google / search engine tags -->
|
||||||
|
{% if REL_CANONICAL_LINK %}
|
||||||
|
<link rel="canonical" href="{{ REL_CANONICAL_LINK }}" />
|
||||||
|
{% endif %}
|
||||||
{% if allow_search_engine_indexing %}
|
{% if allow_search_engine_indexing %}
|
||||||
{% if PAGE_DESCRIPTION %}
|
{% if PAGE_DESCRIPTION %}
|
||||||
<meta name="description" content="{{ PAGE_DESCRIPTION }}" />
|
<meta name="description" content="{{ PAGE_DESCRIPTION }}" />
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ def add_api_url_context(
|
|||||||
context["html_settings_links"] = html_settings_links
|
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):
|
class ApiURLView(TemplateView):
|
||||||
@override
|
@override
|
||||||
def get_context_data(self, **kwargs: Any) -> dict[str, str]:
|
def get_context_data(self, **kwargs: Any) -> dict[str, str]:
|
||||||
@@ -209,6 +213,7 @@ class MarkdownDirectoryView(ApiURLView):
|
|||||||
sidebar_article = self.get_path("include/sidebar_index")
|
sidebar_article = self.get_path("include/sidebar_index")
|
||||||
sidebar_index = sidebar_article.article_path
|
sidebar_index = sidebar_article.article_path
|
||||||
title_base = "Zulip help center"
|
title_base = "Zulip help center"
|
||||||
|
add_canonical_link_context(context, self.request)
|
||||||
elif self.policies_view:
|
elif self.policies_view:
|
||||||
context["page_is_policy_center"] = True
|
context["page_is_policy_center"] = True
|
||||||
context["doc_root"] = "/policies/"
|
context["doc_root"] = "/policies/"
|
||||||
@@ -219,6 +224,9 @@ class MarkdownDirectoryView(ApiURLView):
|
|||||||
else:
|
else:
|
||||||
sidebar_index = None
|
sidebar_index = None
|
||||||
title_base = "Zulip terms and policies"
|
title_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:
|
elif self.api_doc_view:
|
||||||
context["page_is_api_center"] = True
|
context["page_is_api_center"] = True
|
||||||
context["doc_root"] = "/api/"
|
context["doc_root"] = "/api/"
|
||||||
@@ -226,6 +234,7 @@ class MarkdownDirectoryView(ApiURLView):
|
|||||||
sidebar_article = self.get_path("sidebar_index")
|
sidebar_article = self.get_path("sidebar_index")
|
||||||
sidebar_index = sidebar_article.article_path
|
sidebar_index = sidebar_article.article_path
|
||||||
title_base = "Zulip API documentation"
|
title_base = "Zulip API documentation"
|
||||||
|
add_canonical_link_context(context, self.request)
|
||||||
else:
|
else:
|
||||||
raise AssertionError("Invalid documentation view type")
|
raise AssertionError("Invalid documentation view type")
|
||||||
|
|
||||||
@@ -383,6 +392,7 @@ class IntegrationView(ApiURLView):
|
|||||||
context: dict[str, Any] = super().get_context_data(**kwargs)
|
context: dict[str, Any] = super().get_context_data(**kwargs)
|
||||||
add_integrations_context(context)
|
add_integrations_context(context)
|
||||||
add_integrations_open_graph_context(context, self.request)
|
add_integrations_open_graph_context(context, self.request)
|
||||||
|
add_canonical_link_context(context, self.request)
|
||||||
add_google_analytics_context(context)
|
add_google_analytics_context(context)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user