Skip to content

Commit fd5f6f4

Browse files
committed
Appease our great search engine overlords
This hopefully fixes all translated pages showing up in search engine results, and makes the STABLE version of each page canonical. In turn, this allows us to re-enable indexing of the version-specific pages (see robots.txt changes), as search engines should prefer the canonical (stable) version, and only show the other versions if no canonical (stable) version exists (i.e. because that feature is only in latest, or was removed in stable). It adds proper canonical links for all generated pages, and fixes the existing links between the various translations of a page by both ensuring the pages links to itself with the proper language tag, and by properly linking to the full path of other translated versions.
1 parent b4c2083 commit fd5f6f4

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

_templates/layout.html

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
{% extends "!layout.html" %}
2-
{% block linktags %}
3-
<link rel="alternate" hreflang="en" href="https://docs.godotengine.org/en/" />
4-
<link rel="alternate" hreflang="de" href="https://docs.godotengine.org/de/" />
5-
<link rel="alternate" hreflang="es" href="https://docs.godotengine.org/es/" />
6-
<link rel="alternate" hreflang="fr" href="https://docs.godotengine.org/fr/" />
7-
<link rel="alternate" hreflang="ko" href="https://docs.godotengine.org/ko/" />
8-
<link rel="alternate" hreflang="pl" href="https://docs.godotengine.org/pl/" />
9-
<link rel="alternate" hreflang="pt-br" href="https://docs.godotengine.org/pt-br/" />
10-
<link rel="alternate" hreflang="uk" href="https://docs.godotengine.org/uk/" />
11-
<link rel="alternate" hreflang="zh-cn" href="https://docs.godotengine.org/zh-cn/" />
12-
<link rel="alternate" hreflang="x-default" href="https://docs.godotengine.org/" />
13-
{{ super() }}
14-
{% endblock %}
1+
{% extends "!layout.html" -%}
2+
{% block linktags -%}
3+
{% if godot_inject_language_links -%}
4+
{% for alternate_lang in godot_docs_supported_languages -%}
5+
<link rel="alternate" hreflang="{{ alternate_lang }}" href="{{ godot_docs_basepath }}{{ alternate_lang }}/{{ godot_canonical_version }}/{{ pagename }}{{ godot_docs_suffix }}" />
6+
{% endfor -%}
7+
<link rel="alternate" hreflang="x-default" href="{{ godot_docs_basepath }}{{ godot_default_lang }}/{{ godot_canonical_version }}/{{ pagename }}{{ godot_docs_suffix }}" />
8+
9+
<link rel="canonical" href="{{ godot_docs_basepath }}{{ lang_attr }}/{{ godot_canonical_version }}/{{ pagename }}{{ godot_docs_suffix }}" />
10+
{% endif -%}
11+
{{ super() }}
12+
{% endblock -%}

conf.py

+12
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@
4949
tags.add(tag.strip()) # noqa: F821
5050

5151
# Language / i18n
52+
supported_languages = ['en', 'de', 'es', 'fr', 'fi', 'it', 'ja', 'ko', 'pl', 'pt-br', 'ru', 'uk', 'zh-cn']
5253
language = os.getenv("READTHEDOCS_LANGUAGE", "en")
54+
if not language in supported_languages:
55+
print("Unknown language: " + language)
56+
print("Supported languages: " + ", ".join(supported_languages))
57+
print("This is an error or needs to be added to supported_languages in conf.py")
58+
5359
is_i18n = tags.has("i18n") # noqa: F821
5460

5561
exclude_patterns = ["_build"]
@@ -94,6 +100,12 @@
94100
"github_repo": "godot-docs", # Repo name
95101
"github_version": "master", # Version
96102
"conf_py_path": "/", # Path in the checkout to the docs root
103+
"godot_inject_language_links": True,
104+
"godot_docs_supported_languages": supported_languages,
105+
"godot_docs_basepath": "https://docs.godotengine.org/",
106+
"godot_docs_suffix": ".html",
107+
"godot_default_lang": "en",
108+
"godot_canonical_version": "stable",
97109
}
98110

99111
html_logo = "img/docs_logo.png"

robots.txt

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
user-agent: *
2-
disallow: /*/3.2
3-
disallow: /*/3.1
4-
disallow: /*/3.0
5-
disallow: /*/2.1
62

73
sitemap: https://docs.godotengine.org/sitemap.xml

0 commit comments

Comments
 (0)